hdu 3008 Warcraft(dp)

Warcraft

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1144    Accepted Submission(s): 580


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 25 10 5 20 10 30 28 76 70 4 2 25 10 5 20 10 30 28 77 70 0 0 0
 

Sample Output
  
  
4 My 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!
 

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3008

题意:
你是魔兽里的一个英雄,有n个技能,100血和100魔,打攻击力为q血量为100的boss,a[i]代表第i个技能所需要的魔法值,b[i]代表第i个技能的伤害值,t代表你每秒回复的蓝量(满值100,蓝不能超过100)。释放技能需要消耗魔法值,当魔法值不够时不能释放技能,当然你可以选择普通攻击,他不消耗魔法,伤害为1。每秒初可以释放一次普通攻击或技能。每秒末会受到一次boss的攻击。
若你能打死boss请输出最短时间,若不能请输出 My god 。
思路:
简单dp题,完全可以转化成背包问题,看我的转化大法~。
魔力值就是背包的大小V,技能就是物品,技能所需的魔法值就是物品的重量,技能造成的伤害就是物品的价值,(100/q+(100%q)>0)代表可以取得物品个数。dp[i][j]代表第i秒时j魔力时最多造成的伤害(dp[i][j]就是背包体积为j时取i个物品的最大价值)。而怪物的血量100就是给你一个限度,当背包价值达到100时就可以杀死boss了,此时记录下最短时间。开始设最短时间为0,若最终t==0,则没有任何情况满足dp[i][j]>=100,即杀不死boss输出My god。若t!=0,说明能杀死boss,输出t。
提示:可以吧普通攻击当做一个a=0,b=1的技能,第一次满足dp[i][j]>=100时i肯定是最小。

代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
int dp[105][105];
int a[105],b[105];
int maxx(int a,int b){
return a>b?a:b;}
int main(){
    int n,t,q,mo,pd1,i,j,k;
    int c,minn;
    while(scanf("%d%d%d",&n,&t,&q)&&(n||t||q)){
        memset(dp,0,sizeof(dp));
        minn=0;pd1=1;
        n++;
        for(i=2;i<=n;i++)
            scanf("%d%d",&a[i],&b[i]);
        a[1]=0,b[1]=1;
        c=100/q;
        if(100%q)
            c++;
            for(i=1;i<=c&&pd1;i++){
                for(j=0;j<=100&&pd1;j++){
                    for(k=1;k<=n&&pd1;k++){
                        if(a[k]<=j){
                            mo=j+t-a[k];
                            if(mo>100)
                                mo=100;
                            dp[i][mo]=maxx(dp[i][mo],dp[i-1][j]+b[k]);
                            if(dp[i][mo]>=100)
                            {minn=i;pd1=0;break;}
                        }

                    }
                }
            }
            if(minn==0)
                printf("My god\n");
            else
                printf("%d\n",minn);
    }
    return 0;
}





  
  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值