1052. Candy Sharing Game

TAG 模拟

没说N多大。。。水题就直接贴代码了。。

 

/* source code of submission 427279, Zhongshan University Online Judge System */ #include <stdio.h> int n,ans,last; bool equal; int candy[3000]; int main(int argc, char *argv[]) { while ( scanf("%d", &n) && n!=0 ) { for (int i=0; i<n; ++i) { scanf("%d", &candy[i]); } ans=0; equal=true; for (int i=1; i<n; ++i) { if ( candy[i]!=candy[0] ) { equal=false; break; } } if ( equal ) { printf("%d %d/n", 0, candy[0]); } else { do { ++ans; for (int i=0; i<n; ++i) { candy[i]/=2; } last=candy[n-1]; equal=true; for (int i=n-2; i>=0; --i) { candy[i+1]+=candy[i]; if ( candy[i+1]%2==1 ) { ++candy[i+1]; } if ( i<n-2 && candy[i+1]!=candy[i+2] ) { equal=false; } } candy[0]+=last; if ( candy[0]%2==1 ) { ++candy[0]; } equal= equal && candy[0]==candy[1]; if ( equal ) { break; } } while ( true ); printf("%d %d/n",ans, candy[0]); } } return 0; }

你可能感兴趣的:(1052. Candy Sharing Game)