hdu 4950 Monster

Monster

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 590    Accepted Submission(s): 238

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

Source

2014 Multi-University Training Contest 8

题解及代码:

签到题,不多讲,分成三个阶段模拟,第一阶段,看是否能一下就把怪物杀死;第二阶段,进行到第k回合,假设我进行攻击,怪物未回血,看是否能将其杀死;

第三阶段,进行玩第k+1回合,看这几个回合下来怪物是否掉血了。

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    int cas=1;
    long long h,m,n,t;
    while(scanf("%I64d%I64d%I64d%I64d",&h,&m,&n,&t)!=EOF)
    {
        if(!h&&!m&&!n&&!t)
            break;
        if(m<=n)
        {
            if(h<=m)
            {
                printf("Case #%d: YES\n",cas++);
            }
            else
            {
                printf("Case #%d: NO\n",cas++);
            }
            continue;
        }
        if(m*t-n*(t-1)>=h)
        {
            printf("Case #%d: YES\n",cas++);
        }
        else
        {
           if(m*t-n*(t+1)>=1)
            printf("Case #%d: YES\n",cas++);
           else
            printf("Case #%d: NO\n",cas++);
        }
    }
    return 0;
}

hdu 4950 Monster,布布扣,bubuko.com

时间: 2024-10-08 01:22:31

hdu 4950 Monster的相关文章

HDU 4950 Monster(公式)

HDU 4950 Monster 题目链接 题意:给定怪兽血量h,你攻击力a.怪物回血力b,你攻击k次要歇息一次,问是否能杀死怪兽 思路:签到题,注意最后一下假设打死了怪,那么怪就不会回血了 思路: #include <cstdio> #include <cstring> typedef long long ll; ll h, a, b, k; bool solve() { if (a >= h) return true; if (b >= a) return fals

hdu 4950 Monster(数学题,多校8)

题目链接:pid=4950http://acm.hdu.edu.cn/showproblem.php?pid=4950">http://acm.hdu.edu.cn/showproblem.php?pid=4950 Monster Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 220    Accepted Submission

HDU 4950 Monster (贪心算法)

题目链接 题意:有一个怪物的血量为h,人攻击怪物,每回合可以杀掉a滴血,再回b滴血,k个回合之后人会休息一回合,即人不攻击而怪物回b滴血,问能否杀死.翻译过来就是给定一个数h,每轮可以先减a再加b,k轮后会有一轮只加b不减a,如果再这过程中存在h<=0就输出YES,否则输出NO. 题解:注意是先减a再加b,有可能不加b就已经h<=0,先分类讨论ab,如果a比b大那么只有可能第一回合杀死,一旦+b就不可能在杀死了,如果a比b小,讨论在经过k-1轮后第k轮只减不加能否<=0,再讨论k+1轮的

2014多校联合八(HDU 4945 HDU 4946 HDU 4948 HDU 4950 HDU 4951 HDU 4952)

HDU 4945 2048 题意:给你一堆数字  问有几个子集可以拼出2048 思路: 拼数字的规则相当于让数字乘二  所以不是2^i的数字不会拼出2048  那么这些数可选可不选  即为2^cnt种可能 之后只要计算出有几个子集不可能拼出2048即可  不过简单的直接dp是2048*100000的复杂度的  会TLE 所以要变成先枚举元素  再枚举该种元素个数  再枚举2048种状态  然后利用组合求(组合里需要逆元) 为什么这样快?  因为比如枚举2^5这个元素的时候  最多取2^6个  枚

hdu 4950

#include<stdio.h> int main(){ __int64 h,a,b,k,j=0; while(scanf("%I64d%I64d%I64d%I64d",&h,&a,&b,&k),h||a||b||k) { printf("Case #%I64d: ",++j); if(h<a+1) { printf("YES\n"); continue; } if(a<=b) { pri

多校比赛第九场

hdu 4950 Monster 题意好简单,队友说要用线段树做,要不然会TLE,连树状数组也会T.我说让我试试树状数组,结果搞了一个 小时左右用树状数组给搞出来了,嘿嘿.用了树状数组区间更新. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 100010 using namespace std; __int64 a[maxn],c[

hdu4950 Monster (水题)

4950 Monster Monster Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 52 Accepted Submission(s): 29 Problem Description Teacher Mai has a kingdom. A monster has invaded this kingdom, and Teacher Mai

简单题

原题http://acm.hdu.edu.cn/showproblem.php?pid=4950 Monster Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 566    Accepted Submission(s): 231 Problem Description Teacher Mai has a kingdom. A mons

hdu 4970 killing monster 代代相传刷qq 不用线段树啦~

[题意]塔防游戏,一条n长的路上,有m个炮台,可以覆盖[li,ri]范围,威力ci,即每一秒,炮塔可以对范围 内的怪物可以造成ci点伤害.只有有q只怪物,每只怪物有hi点血,出现位置为xi:当怪物血量减少到0或以下时消失,怪物一直朝n位置前进.问有几只怪物可以离开这条路. [题解]用线段树可以做,不过还好我们有代代相传的刷qq 算法 ,让解法变得简单的多~    ^_^ 1 #include <iostream> 2 #include <cstdio> 3 #include <