All the students circle around the teacher. Each student starts with an even number of candy blocks. Each time the teacher blows a whistle, each student gives half of the candy in his hands to the students on the right, after the whistle, when the number of candy in the hand is odd, the teacher will fill it with him or her. In this way, when the number of candy in each student's hand is the same, the game ends.
Input requirement: there are more than one game test. For each game test, enter the number of students n, and the number of sweets (even) in each student's hand at the beginning ), the test ends when the number of students is 0.
Output requirements: For each game test, the number of sweets in the hands of the students is the same after the instructor blew several whistle, and the number of candy in the same row is the same.
Standard Input: 6
36
2
2
2
2
2
4
2
4
6
8
Standard output: 15 14
4 8
The output of the solution is different from the instance output, mainly because the number of whistle-blowing times varies by the Teacher:
# Include <iostream>
Using namespace STD;
Void Arun (int * a, int nlen, int * n, int * How)
{
Int J, T1, T2;
Int I = 0;
While (1)
{
I ++;
T2 = A [nlen-1]/2;
For (j = 0; j <nlen; j ++)
{
T1 = A [J]/2;
A [J] = t1 + T2;
T2 = T1;
}
For (j = 1; j <nlen; j ++)
{
If (A [0]! = A [J])
Break;
}
If (j = nlen ){
* N = I;
* How = A [0];
Return;
}
For (j = 0; j <nlen; j ++)
{
If (A [J] % 2 = 1) A [J] ++;
}
}
}
Int main ()
{
Int N, how;
While (1)
{
If (CIN> N)
{
If (n <= 0) break;
Int * A = (int *) New int [N];
For (INT I = 0; I <n; I ++)
{
Cin> A [I];
}
Arun (A, N, & N, & how );
Delete [];
Cout <n <"" }
Else break;
}
Return 0;
}