HDU:Warcraft

来源:互联网 发布:c语言 algin 编辑:程序博客网 时间:2024/06/08 10:34

Warcraft

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 0   Accepted Submission(s) : 0

Font: Times New Roman | Verdana | Georgia

Font Size: 

Problem Description

Have you ever played the Warcraft?It doesn't matter whether you have played it !We will give you such an experience.There are so many Heroes in it,but you could only choose one of them.Each Hero has his own skills.When such a Skill is used ,it costs some MagicValue,but hurts the Boss at the same time.Using the skills needs intellegence,one should hurt the enemy to the most when using certain MagicValue.

Now we send you to complete such a duty to kill the Boss(So cool~~).To simplify the problem:you can assume the LifeValue of the monster is 100, your LifeValue is 100,but you have also a 100 MagicValue!You can choose to use the ordinary Attack(which doesn't cost MagicValue),or a certain skill(in condition that you own this skill and the MagicValue you have at that time is no less than the skill costs),there is no free lunch so that you should pay certain MagicValue after you use one skill!But we are good enough to offer you a "ResumingCirclet"(with which you can resume the MagicValue each seconds),But you can't own more than 100 MagicValue and resuming MagicValue is always after you attack.The Boss is cruel , be careful!

Input

There are several test cases,intergers n ,t and q (0<n<=100,1<=t<=5,q>0) in the first line which mean you own n kinds of skills ,and the "ResumingCirclet" helps you resume t points of MagicValue per second and q is of course the hurt points of LifeValue the Boss attack you each time(we assume when fighting in a second the attack you show is before the Boss).Then n lines follow,each has 2 intergers ai and bi(0<ai,bi<=100).which means using i skill costs you ai MagicValue and costs the Boss bi LifeValue.The last case is n=t=q=0.

Output

Output an interger min (the minimun time you need to kill the Boss)in one line .But if you die(the LifeValue is no more than 0) ,output "My god"!

Sample Input

4 2 2510 520 1030 2876 704 2 2510 520 1030 2877 700 0 0

Sample Output

4My god

Hint

Hint:
When fighting,you can only choose one kind of skill or just to use the ordinary attack in the whole second,the ordinary attack costs the Boss 1 
points of LifeValue,the Boss can only use ordinary attack which costs a whole second at a time.Good Luck To You!


每一回合boss对人的伤害都是固定的,人被上海了,他的生命值是不会回复的,但是魔法值可以恢复,如果100%q==0,则人可以和boss对打time=100/q个回合,否则可以对打time=100/q+1回合。然后就讨论认在这几个回合中能否将boss打倒,
dp[j-skill[k].bi]=max(dp[j-skill[k].bi],dp[j]-skill[k].ai+t);   dp[j],代表boss血量为j的时候英雄所剩的最大魔法值,因为魔法值越大对人越有利。

题目代码:
#include <stdio.h>  
#include <string.h>  
typedef struct{  
    int ai; //消耗的魔法值 
    int bi;  //伤害值
}node;  
int max (int a,int b)  
{  
    return a > b ? a : b ;  
}  
int main ()  
{  
    node skill[110];  
    int n,t,q,i,j,k,p;  
    int dp[110];   //dp[j]代表boss血量为j时英雄所有的最大魔法值
    while (scanf ("%d%d%d",&n,&t,&q)) //n种技能,t打一次恢复t点魔法值,q为boss的伤害值
    {  
        p = 0;  //代表状态,
        if (n == 0 && t == 0 && q == 0)  
            break;  
        for (i = 1 ; i <= n ; i++)  
            scanf ("%d%d",&skill[i].ai,&skill[i].bi);  //输入n中技能
        skill[0].ai = 0;  //普通技能魔法耗费值 
        skill[0].bi = 1;  //普通技能伤害值
        memset (dp,-1,sizeof(dp));  //初始化为-1
        dp[100] = 100; //boos满血时,英雄的魔法也是满的 
        int time = (100 % q == 0) ? 100/q : 100 / q + 1 ;//英雄在time回合内要打倒boss;  
        for (i = 1 ; i <= time ; i ++)  
        {  
            for (j = 1 ; j <= 100 ; j ++)  
            {  
                if (dp[j] == -1)  
                    continue;  
                for (k = 0 ; k <= n ; k ++)  
                {  
                    if (j <= skill[k].bi && dp[j] >= skill[k].ai)  //如果boss当前血量小于当前技能的伤害值,且英雄有足够的魔法值使用这种技能
                    {  
                        printf ("%d\n",i); //boss直接在这个之间被打死,输出时间i
                        p = 1;  //让 p=1代表boss被打死了
                        break;   //循环结束
                    }  
                    else if (j > skill[k].bi && dp[j] >= skill[k].ai) //如果boss血量比当前技能伤害值大,我要讨论,用这种技能和不用这种技能,的最小值 
                    {  
                        dp[j - skill[k].bi] = max (dp[j - skill[k].bi],dp[j] - skill[k].ai + t); 
                        if (dp[j + skill[k].bi] > 100) //如果我用了后,英雄的魔法值大于100了,英雄的魔法值不能超过100
                            dp[j + skill[k].bi] = 100;  
                    }  
                }  
                if (p)  //只要有解就结束
                    break;  
            }  
            if(p)  
                break;//只要有解就结束  

        }  
        if (!p)  //如果无解,英雄被boss打死。
            printf ("My god\n");      
    }  
}  
0 0
原创粉丝点击