题目链接:
把题意模拟出来就可以了,不多说。
#includeusing namespace std;const int LEN = 10000;int input[LEN],pass[LEN];int len;int isEnd(){ int pre = input[0]; for (int i = 0;i < len;i ++) { if (input[i] != pre) return 0; pre = input[i]; } return 1;}void passCandy(){ //每个人要传给其右边的人的糖果数 for (int i = 0;i < len;i ++) pass[i] = input[i] / 2; for (int i = 0;i < len;i ++) { if (i == 0) input[i] = input[i] - pass[i] + pass[len - 1]; else input[i] = input[i] - pass[i] + pass[i - 1]; }}void turnEven(){ for (int i = 0;i < len;i ++) if (input[i] % 2 != 0) input[i] ++;}int main (){ while (scanf("%d",&len) != -1 && len != 0) { for (int i = 0;i < len;i ++) scanf("%d",&input[i]); int roundNum = 0; //检查是否结束 while (!isEnd()) { passCandy(); //将单数的变成双数 turnEven(); roundNum ++; } printf("%d %d\n",roundNum,input[0]); } return 0;}