BZOJ系列3856《Monster》题解

来源:互联网 发布:明星语音模拟软件 编辑:程序博客网 时间:2024/06/06 03:59

Description

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".

Sample Input

5 3 2 2
0 0 0 0

Sample Output

Case #1: NO

英语题目,先说一下题意:

一个怪物,初始H点血,每回合可以打一下掉A点血,回合结束时怪物可以回B点血。

连续攻击K回合后,需要休息一回合。

当怪物血量小于1时死亡。

问:怪物能否死亡。


分析:

模拟。

很容易忽略情况,怪物死的情况有3种:

1.怪物第一回合就会死。

2.怪物在第K回合或第K回合前会死。

3.每K+1个回合怪物就会少一些血,直到怪物死亡。

除以上三种外,怪物都不会死亡。

(注意:数据范围!!!)

代码如下:

#include<iostream>#include<cmath>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;long long H,A,B,K,i=0;int main(){    for(;;)    {        scanf("%lld%lld%lld%lld",&H,&A,&B,&K);        if(H==0&&A==0&&B==0&&K==0) return 0;if(A>=H||K*A-(K-1)*B>=H||K*A>(K+1)*B) printf("Case #%d: YES\n",++i);//1.第一回合就可以杀死。2.第k或第k前可以杀死。3.每k个回合血都变少,总会杀死。else printf("Case #%lld: NO\n",++i);//否则杀不死。    }    return 0;}


0 0