For a piece of n*m chocolate, Alice can only cut vertically, cut into a*m and b*m, and a+b=n,bob can only be cut into the cross, only into A*n and B*n, and a+b=m.
For n*n of this kind of chocolate, who first cut the first knife, directly let the other side has the opportunity to cut two knives, so Alice could not cut this chocolate, can directly ignore this.
After a person will try to choose the former one cut after a small piece of cut.
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath>using namespaceStd;typedefLong LongLL;intN,T;LL x,Y;intMain(){scanf("%d",&T); for (intI=1;I<=T;I++) {scanf("%d",&N);LL K1=0,K2=0; while (N--) {scanf("%lld%lld",&X,&Y); while (X>1&&Y>1)X>>=1,Y>>=1,K1++,K2++;if (X==1)K2+=Y-1;ElseK1+=X-1; }if (K1<=K2)Printf("Case%d:bob\n",I);ElsePrintf("Case%d:alice\n",I); }return0;}
"hdu3544" Alice ' s Game