天天看點

杭電acm 1034題

problem description

a number of students sit in a circle facing their

teacher in the center. each student initially has an even number of pieces of

candy. when the teacher blows a whistle, each student simultaneously gives half

of his or her candy to the neighbor on the right. any student, who ends up with

an odd number of pieces of candy, is given another piece by the teacher. the

game ends when all students have the same number of pieces of

candy. 

write a program which determines the number of times the teacher

blows the whistle and the final number of pieces of candy for each student from

the amount of candy each child starts with.

input

the input may describe more than one game. for each

game, the input begins with the number n of students, followed by n (even) candy

counts for the children counter-clockwise around the circle. the input ends with

a student count of 0. each input number is on a line by itself.

output

for each game, output the number of rounds of the

game followed by the amount of candy each child ends up with, both on one

line.

sample input

6 36 2 2 2 2 2 11 22 20 18 16 14 12 10 8 6 4 2 4 2 4 6 8 0

sample output

15 14 17 22 4 8

hintthe game ends in a finite number of steps because: 1.

the maximum candy count can never increase. 2. the minimum candy count can never

decrease. 3. no one with more than the minimum amount will ever decrease to the

minimum. 4. if the maximum and minimum candy count are not the same, at least

one student with the minimum amount must have their count increase.

 這道題的大意是n個開始都拿着偶數顆糖的小朋友圍着老師坐,老師一吹哨子同時給自己右手邊的同學自己一半的糖,結束後奇數顆糖的同學老師會給一顆糖補成偶數棵,直到大家手上的糖一樣數目...問需要玩幾次,以及最後糖的數量是多少?