BZOJ系列3856《Monster》題解

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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章