欢迎光临散文网 会员登陆 & 注册

CF 1792A - GamingForces

2023-06-26 14:48 作者:您是打尖儿还是住店呢  | 我要投稿

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 正在玩电脑游戏。 他要杀死 n 个怪物,其中第 i 个的生命值很高。


Monocarp 的角色有两个法术,他可以以任意顺序施展任意次数(可能为零):

选择恰好两个活着的怪物并将其生命值降低 1;

选择一个怪物并杀死它。

当怪物的生命值变为0时,它就会死亡。

为了杀死所有怪物,Monocarp 最少需要施展多少次法术?

---------------------------------------------------------------

对于生命值大于1的怪物,肯定是一招消灭掉最省时间了,只有是生命值为1的怪物才有一次选2个怪物,然后生命值-1的必要,于是就是求数组中1的怪物的数量即可;

当然还要判断一下奇数还是偶数;

下面是代码:


CF 1792A - GamingForces的评论 (共 条)

分享到微博请遵守国家法律