| 比赛 | 
    20120711 | 
    评测结果 | 
    AAAAAWWWAWAA | 
    | 题目名称 | 
    平衡奶牛 | 
    最终得分 | 
    66 | 
    | 用户昵称 | 
    TBK | 
    运行时间 | 
    0.193 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    0.70 MiB  | 
    | 提交时间 | 
    2012-07-11 10:05:30 | 
显示代码纯文本
#include <iostream> 
#include <cmath> 
#include <cstring> 
#include <string> 
#include <cstdio> 
#include <cstdlib> 
#include <iomanip> 
#include <set> 
#include <map>
#include <algorithm> 
#define MAXN 0x7fffffff 
using namespace std; 
int a[100001],b,c,d,t,s;
map <int,int> m;
map <int,int>::iterator l,n;
int main(void)
{
	freopen ("balline.in","r",stdin);
	freopen ("balline.out","w",stdout);
    scanf("%d%d",&b,&c);
	c=(int)pow(2.0,(double)c)-1;
	for (d=1;d<=b;d++) scanf("%d",&a[d]);
	for (d=1;d<=b;d++)
	{
		a[d]+=a[d-1];
		a[d]%=c;
	}
	m[0]=0;
	for (d=1;d<=b;d++)
	{
 		l=m.find(a[d]);
		if (l==m.end()) m[a[d]]=d;
			else 
			{
				t=d-m[a[d]];
				if (t>s) s=t;
			}
	}
	printf("%d",s);
	fclose(stdin); 
    fclose(stdout); 
    return 0; 
}