Blue Bridge-Points candy (algorithm training)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.