1 /*2 Blue Bridge-minute sweets3 Test Pass4 Time: 2015-9-225 6 Problem Description7 there are N children sitting around in a circle. The teacher gave each child a random number of candies and then played the following games:8 9 each of the children gave their sweets half to the children on the left hand side. Ten One after a round of sugar, the children with odd sugars were supplied with 1 sweets by the teacher and turned into an even number. A - repeat the game until all the children have the same number of candies. - the your task is to predict how many candies a teacher will need to reissue in a known initial candy situation. - Input Format - The program first reads an integer N (2<n<100), which indicates the number of children. - Next is a line of n even numbers separated by a space (each even number is not greater than 1000, not less than 2) + output Format - ask the program to output an integer that indicates the number of sweets the teacher needs to reissue. + Sample Input A 3 at 2 2 4 - Sample Output - 4 - */
-#include <stdio.h> - #defineN 100 in intJudge (intP[],intnum) { - inti; to for(i =0; i < num; i++) + if(p[0] !=P[i]) - return 1; the return 0; * } $ intMain () {Panax Notoginseng intChild[n] = {0}, T[n] = {0}; - intn, I; thescanf"%d", &n); + for(i =0; I < n; i++) { Ascanf"%d", &child[i]); the } + - intsum =0; $ intCount =0; $ while(Judge (Child, N)) { - for(i =0; I < n; i++) { - if(Child[i]%2==0) { theT[i] = Child[i] = child[i]/2; - }Wuyi Else { theT[i] = child[i] = (Child[i] +1) /2; -sum++; Wu } - } About for(i =0; I < n-1; i++) { $Child[i +1] +=T[i]; - } -child[0] + = T[n-1]; -count++; A } + //printf ("%d sugars required,%d sweets required", count, sum); theprintf"%d", sum); -}
Blue Bridge-Points candy (algorithm training)