Test instructions: Jerry, Tom play games, give you out of n boxes, a[i] for the initial, the number of small balls in the first. Jerry can then add a 0 or K-fold ball to each box, and after that, Jerry will rearrange the boxes, and if I have a small ball in the box I, Jerry will win, output "Jerry" or Output "Tom".
Analysis: First count each number of balls have how many boxes, then from small to Oita past, the rest of the box to i+k position, so scan the array, if more than one and more than a number of balls can not find the corresponding box Tom wins, otherwise Jerry wins.
#include <iostream>using namespace Std;int main () {int m,n,k,x,i;int cnt[105];bool F;ios::sync_with_stdio (False) ; Cin>>m;while (m--) {Cin>>n>>k;memset (cnt,0,sizeof (CNT)); for (i=0;i<n;i++) cnt[cin>>x,x ]++;f=true;for (i=1;i<=n;i++) {if (!cnt[i]) {f=false;break;} Cnt[i+k]+=cnt[i]-1;} if (f) cout<< "Jerry" <<endl;elsecout<< "Tom" <<ENDL;} return 0;}
HDU ACM 5090 Game with pearls-> binary graph Max match or?