Time limit of previous questions: 1.0s memory limit: 256.0MBProblem description 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:
Each of the children gave their sweets half to the children on the left hand side.
After a round of sugar, the children with odd sugars were supplied with 1 sweets by the teacher and turned into an even number.
Repeat the game until all the children have the same number of candies.
Your task is to predict how many candies a teacher will need to reissue in a known initial candy situation. The input Format 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 is not greater than 1000, not less than 2) output format requires the program output an integer, indicating the teacher needs to reissue the number of sweets. Sample Input 3
2 2 4 Sample output 4 Thinking of solving problemsdirectly follow the test instructions with a while loop, until the number of sweets want to wait for the end, and output a total number of replacement candyOne thing to note is that if you use a for loop to make a direct change to num[i], because it is affected by both itself and the data on the left, and the data is composed of a ring, the final data will be in error whenever the One o'clock starts, so define an array to cache the data.
Code
#include <stdio.h>int num[110],temp[110];int Main () {int n;int i,j,k;int ok,sum;while (scanf ("%d", &n)!=eof) { for (i=1;i<=n;i++) scanf ("%d", &num[i]), Ok=0;sum=0;while (!ok) {for (i=1;i<=n;i++) {// Judge whether the data is equal if (Num[i]==num[i+1]) { if (i==n-1) ok=1; } by looping to determine whether the adjacent two are equal and whether the data is fully cycled//. else break ;} After one operation num[i]==num[i+1]/2+num[i]/2//the operation into two steps, creating a new array to buffer the for (i=1;i<=n;i++) {if (i==1) TEMP[N]=NUM[I]/2; else TEMP[I-1]=NUM[I]/2;} for (i=1;i<=n;i++) {num[i]=num[i]/2+temp[i];if (num[i]%2==1) {sum++;num[i]++;}}} printf ("%d\n", sum);} return 0;}
1503140001-Blue Bridge Cup-previous question points candy