hdu 4950

Monster

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3223    Accepted Submission(s): 969


Problem 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轮第k+1轮暂停休息(也可以在k之内的任意轮进行休息),此时怪兽也恢复b血量,问是否可以在无限轮之后杀死怪兽
  首先看特殊情况:若a > h,可以直接杀死怪,直接输出YES;然后若 a <= b,无论怎么杀,都无法满足,输出NO
  再看一般情况:若想要杀死怪,那么必定是一次性进行k轮,才能使对怪的伤害最大。那么如果能杀死怪,一定是第i(1 <= i < k)轮完成后,再进行第i+1轮之中,即h - i(a-b) - a <= 0 则一定能杀死怪,
  即判断 1 <= ⌈(h-a)/(a-b)⌉ < k 是否成立,成立直接输出YES,不成立则进一步判断k轮结束时怪的血量+b是否比初始血量少,若比初始血量少则说明后面经过无限轮回一定可以杀死怪,否则不可能
 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int N = 505;
int t, n, m, ans;
ll h, a, b, k;
int main(){
    t = 1;
    while(scanf("%I64d%I64d%I64d%I64d", &h, &a, &b, &k)){
        if(h+a+b+k == 0)
            break;
        printf("Case #%d: ", t++);
        if(a >= h){
            printf("YES
");
            continue;
        }
        if(a <= b){
            printf("NO
");
            continue;
        }
        int pos = (h-a)%(a-b) ? (h-a)/(a-b)+1:(h-a)/(a-b);
        if(1 <= pos && pos < k){
            printf("YES
");
        }else if(k*(a-b) <= b){
            printf("NO
");
        }else{
            printf("YES
");
        }
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/microcodes/p/12827671.html