37. Candy Sharing Game(待做)

題目描述

A number of students sit in a circle facing their teacher in the center. Each student initially has an 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.

輸入描述:

The input may describe more than one game. For each game, the input begins with the number N of students,followed by N candy counts for the children counter-clockwise around the circle. Each input number is on a line by itself.

輸出描述:

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.

The 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

示例1

輸入

6
36
2
2
2
2
2

輸出

15 14
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末井厌,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子捞烟,更是在濱河造成了極大的恐慌寻馏,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,525評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件肿嘲,死亡現(xiàn)場離奇詭異滑燃,居然都是意外死亡往果,警方通過查閱死者的電腦和手機疆液,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,203評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來棚放,“玉大人,你說我怎么就攤上這事馅闽∑牵” “怎么了?”我有些...
    開封第一講書人閱讀 164,862評論 0 354
  • 文/不壞的土叔 我叫張陵福也,是天一觀的道長局骤。 經(jīng)常有香客問我,道長暴凑,這世上最難降的妖魔是什么峦甩? 我笑而不...
    開封第一講書人閱讀 58,728評論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮现喳,結果婚禮上凯傲,老公的妹妹穿的比我還像新娘。我一直安慰自己嗦篱,他們只是感情好冰单,可當我...
    茶點故事閱讀 67,743評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著灸促,像睡著了一般诫欠。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上浴栽,一...
    開封第一講書人閱讀 51,590評論 1 305
  • 那天荒叼,我揣著相機與錄音,去河邊找鬼典鸡。 笑死被廓,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的萝玷。 我是一名探鬼主播伊者,決...
    沈念sama閱讀 40,330評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼间护!你這毒婦竟也來了亦渗?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,244評論 0 276
  • 序言:老撾萬榮一對情侶失蹤汁尺,失蹤者是張志新(化名)和其女友劉穎法精,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,693評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡搂蜓,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,885評論 3 336
  • 正文 我和宋清朗相戀三年狼荞,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片帮碰。...
    茶點故事閱讀 40,001評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡相味,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出殉挽,到底是詐尸還是另有隱情丰涉,我是刑警寧澤,帶...
    沈念sama閱讀 35,723評論 5 346
  • 正文 年R本政府宣布斯碌,位于F島的核電站一死,受9級特大地震影響,放射性物質發(fā)生泄漏傻唾。R本人自食惡果不足惜投慈,卻給世界環(huán)境...
    茶點故事閱讀 41,343評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望冠骄。 院中可真熱鬧伪煤,春花似錦、人聲如沸凛辣。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,919評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽蟀给。三九已至蝙砌,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間跋理,已是汗流浹背择克。 一陣腳步聲響...
    開封第一講書人閱讀 33,042評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留前普,地道東北人肚邢。 一個月前我還...
    沈念sama閱讀 48,191評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像拭卿,于是被迫代替她去往敵國和親骡湖。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,955評論 2 355

推薦閱讀更多精彩內(nèi)容