Monster
Teacher Mai has a kingdom. A monster has invaded this kingdom, and Teacher Mai wants to kill it.
Monster initially has h HP. And it will die if HP is less than 1.
Teacher Mai and monster take turns to do their action. In one round, Teacher Mai can attack the monster so that the HP of the monster will be reduced by a. At the end of this round, the HP of monster will be increased by b.
After k consecutive round’s attack, Teacher Mai must take a rest in this round. However, he can also choose to take a rest in any round.
Output “YES” if Teacher Mai can kill this monster, else output “NO”.
Input
There are multiple test cases, terminated by a line “0 0 0 0”.
For each test case, the first line contains four integers h,a,b,k(1<=h,a,b,k <=10^9).
Output
For each case, output "Case #k: " first, where k is the case number counting from 1. Then output “YES” if Teacher Mai can kill this monster, else output “NO”.
题意:
题意很简单,就是一个怪兽初始血量为h,你的攻击伤害为a,每回合怪兽回血为b,没k回合你就得休息一回合,但怪兽不休息,判断你是否能打死它
思路:
那就分情况来讨论
1、当你的伤害a比怪兽血多的时候,直接杀死,不用管它回多少血,你是先手
2、当你的伤害a比怪兽的血少,并且比回血也少的时候,不管怎么打都打不死
3、当你k回合的伤害比k+1回合的回血多的时候,也一定能打死,慢慢耗
4、在k回合内杀死的话,就需要k回合的伤害比k-1回合的回血和初始血量的和大
#include<stdio.h>
#include<algorithm>
int main()
{
long long h,a,b,k;
long long i=0;
while(~scanf("%lld%lld%lld%lld",&h,&a,&b,&k)&&(h||a||b||k))
{
i++;
if(h<=a)//第一种情况
printf("Case #%lld: YES\n",i);
else if(b>=a)//第二种情况
printf("Case #%lld: NO\n",i);
else if(k*(a-b)-b>0)//第三种情况
printf("Case #%lld: YES\n",i);
else if((a-b)*(k-1)+a>=h) //第四种情况
printf("Case #%lld: YES\n",i);
else
printf("Case #%lld: NO\n",i);
}
return 0;
}