CF 1792A - GamingForces
Monocarp is playing a computer game. He's going to kill n monsters, the i-th of them has hi health.
Monocarp's character has two spells, either of which he can cast an arbitrary number of times (possibly, zero) and in an arbitrary order:
choose exactly two alive monsters and decrease their health by 1;
choose a single monster and kill it.
When a monster's health becomes 0, it dies.
What's the minimum number of spell casts Monocarp should perform in order to kill all monsters?
Monocarp 正在玩電腦游戲。 他要?dú)⑺?n 個(gè)怪物,其中第 i 個(gè)的生命值很高。
Monocarp 的角色有兩個(gè)法術(shù),他可以以任意順序施展任意次數(shù)(可能為零):
選擇恰好兩個(gè)活著的怪物并將其生命值降低 1;
選擇一個(gè)怪物并殺死它。
當(dāng)怪物的生命值變?yōu)?時(shí),它就會(huì)死亡。
為了殺死所有怪物,Monocarp 最少需要施展多少次法術(shù)?
---------------------------------------------------------------
對(duì)于生命值大于1的怪物,肯定是一招消滅掉最省時(shí)間了,只有是生命值為1的怪物才有一次選2個(gè)怪物,然后生命值-1的必要,于是就是求數(shù)組中1的怪物的數(shù)量即可;
當(dāng)然還要判斷一下奇數(shù)還是偶數(shù);
下面是代碼: