HDU 3008 Warcraft (动态规划)【打怪类】

来源:互联网 发布:vb调用matlab的dll 编辑:程序博客网 时间:2024/05/19 17:05

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,现在BOSS有100滴血(假设),而你有100滴血和100的法术值,BOSS 只有普通攻击,而你有N个技能,这些技能每秒只能放一个,而且每放一个技能 i ,花费cust【i】点法术值,同时打掉BOSS hurt【i】的血量,当然,你也可以选择用普通攻击,普攻不消耗法术值,但是对BOSS 伤害值只有 1 ,(真坑),还有,为了帮助你秒怪,你每秒会回复t点法术值。

现在问你最少多少秒可以消灭BOSS,如果消灭不了,输出My god 。


这题跟背包问题比较像,就是多了一个技能选择和回复法术值,这就多加一层循环就好了,代码自己理解理解。

 【AC代码】

#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int N=105;int n,t,q;int hurt[N],cust[N];int dp[N][N];int min(int x,int y){    return x>y?y:x;}int main(){    while(~scanf("%d%d%d",&n,&t,&q)&& n+t+q)    {        n++;//为了加上普攻        for(int i=2;i<=n;++i)            scanf("%d %d",&cust[i],&hurt[i]);        for(int i=0;i<=102;i++)            for(int j=0;j<=102;j++)//小心越界  注意数组范围            dp[i][j]=100;        int num=100/q;//这是你最多能攻击的次数,再多你就被怪杀死了         if(100%q) num++;// 注意你本身是不会回复血量的        cust[1]=0;//普攻        hurt[1]=1;        int ans=0;        for(int i=1;i<=num;i++)        {            for(int j=0;j<=100;++j)            {                int w=min(100,j+t);//回复法术值                for(int k=1;k<=n;++k)                {                    if(j+cust[k]<=100)                    {                        dp[i][w]=min(dp[i][w],dp[i-1][j+cust[k]]-hurt[k]);//注意第一个dp要用回复法术值后的剩余法术值来算                    }//j+cust[k]表示上一次技能释放前的法术值  第三个DP整体表示上一次释放法术后怪的剩余血量                }                if(dp[i][w]<=0)//如果怪血量少于等于0  就直接跳出                {                    ans=i;                    i=num;                    break;                }            }        }        if(ans==0) printf("My god\n");        else            printf("%d\n",ans);    }    return 0;}



希望我讲解的能让你明白,蟹蟹~~


原创粉丝点击