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 |
难道真的有规律? 直接暴力解决试试~~就算看不出规律,笨办法总是可以想的 以下是代码 #include"stdio.h" #include"stdlib.h" void swap(int *a,int *b) { int temp; temp=(*a+1)%2; *a=(*b+1)%2; *b=temp; } void trans(int a[],long end) { int *pstart,*pend; pstart=&a[1]; pend=&a[end]; while(pstart++<pend--) swap(pstart,pend); } int check(int a[],long m) { int flag=1; long i; for(i=1;i<=m;i++) if(a[i]==1) ; else { flag=0; break;} return flag; } int main() { int *a, t; long m; __int64 n=0, t0; scanf("%d",&t); while(t--) { long i; scanf("%ld",&m); a=(int *)malloc( (m+1)*sizeof(int) ); for(i=1;i<=m;i++) a[i]=1; n=0; while(1){ n++; t0=n%m; if(t0==1||m==1) a[1]=(a[1]+1)%2; else if(t0==0) trans(a,m); else trans(a,t0); if( check(a,m) ) {printf("%lld\n",n); break; } } } return 0; } (不过似乎结果有问题,各位看了的直接指出无妨!) Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator