Previous Test points candyTime limit: 1.0s memory limit: 256.0MB Problem 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
#include <iostream>#include<cstring>using namespacestd;inta[ -];intOkintN) { for(intI=2; i<=n;i++) { if(a[i]!=a[i-1]) return 0; } return 1;}intMainvoid){ intN; while(cin>>N) {memset (A,0,sizeof(a)); intCount=0; for(intI=1; i<=n;i++) {cin>>A[i]; } while(!OK (n)) { intT; for(intI=1; i<=n;i++) { if(i==1) {T=a[i]/2; A[i]=T; } Else{a[i-1]+=a[i]/2; A[i]/=2; }} A[n]+=T; for(intI=1; i<=n;i++) { if(a[i]%2) {A[i]++; Count++; } }} cout<<count<<Endl; } return 0;}
Previous Test points Candy