http://lx.lanqiao.org/problem.page?gpid=T124
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 analysis: Simulate two states with two arrays: a gift between the children, after the teacher assigned. Until the number of sweets in the hands of children are even when the output can be. AC Code:
1#include <stdio.h>2#include <algorithm>3#include <iostream>4#include <string.h>5#include <string>6#include <math.h>7#include <stdlib.h>8#include <queue>9#include <stack>Ten#include <Set> One#include <map> A#include <list> -#include <iomanip> -#include <vector> the #pragmaComment (linker, "/stack:1024000000,1024000000") - #pragmaWarning (disable:4786) - - using namespacestd; + - Const intINF =0x3f3f3f3f; + Const intMax =10000+Ten; A Const DoubleEPS = 1e-8; at Const DoublePI = ACOs (-1.0); - inta[1010], b[1010]; - - voidRunintNintans) - { - intI, first =0; in for(i =0; i < n-1; i + +) - if(A[i]! = a[i +1]) toFirst =1; + if(first) - { the for(i =0; i < N;i + +) * { $ if(A[i]%2==1)Panax Notoginseng { -A[i] + +; theAns + +; + } A } the + for(i =1; i < N;i + +) - { $B[i] = (A[i] + a[i-1]) /2; $ } - -b[0] = (A[n-1] + a[0]) /2; the - for(i =0; i < N;i + +)Wuyi { theA[i] =B[i]; - } Wu - run (n, ans); About } $ Else -printf"%d\n", ans); - } - A intMain () + { the intN, I, j, ans =0; -scanf"%d",&n); $ for(i =0; i < N;i + +) thescanf"%d",&a[i]); the the run (n, ans); the - return 0; in}View Code
Previous Test points Candy