Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
纪念1A(附代码)#include<vector> #include<cstdio> #include<string.h> using namespace std; const int prime=500; vector<int>ha[prime]; int n,m,i,t,su,tot,ma=0,c[100001][31],sum[100001][31],j,k,x; long long lo; bool cmp(int x,int y) { t=0; while(c[x][t]==c[y][t]&&t<m)t++; return t==m?1:0; } int main() { scanf("%d%d",&n,&m); memset(sum,0,sizeof(sum)); memset(c,0,sizeof(c)); for(i=1;i<=n;++i) { scanf("%lld",&lo); for(j=0;j<m;++j) { x=lo%2; lo/=2; sum[i][j]=sum[i-1][j]+x; } } for(i=1;i<=n;++i) { su=0; tot=0; for(j=0;j<m;++j) { c[i][j]=sum[i][j]-sum[i][0]; if(!c[i][j])tot++; su=(su+c[i][j])%prime; } if(tot==m&&i>ma)ma=i; if(su<0)su*=-1; ha[su].push_back(i); } for(i=0;i<prime;++i) { if(ha[i].size()>1) for(j=0;j<ha[i].size()-1;++j) for(k=j+1;k<ha[i].size();++k) if(cmp(ha[i][j],ha[i][k])&&ha[i][k]-ha[i][j]>ma)ma=ha[i][k]-ha[i][j]; } printf("%d\n",ma); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator