zoukankan      html  css  js  c++  java
  • HDU 3008 Warcraft

    Warcraft

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

    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!
     
    Source
     
    Recommend
    gaojie
     
     
     
     

    思路:题目变量有点多,但是有些是不变的,所以定义状态的时候可以把这些忽略掉,然后很明显可以定义状态了,定义完状态之后发现其实是一个01背包,然后照着01背包的思路写就对了;

    定义状态dp[magic_value][attack_times],左边下标对应攻击完第k次后,右边下标对应的值为剩下的魔法值,数组的值为boss剩下的血量。

    状态转移方程

    dp[magic_value][k] = max(dp[magic_value][k] , dp[j][k - 1] + skill[i].dps);

     

     

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    
    using namespace std;
    
    const int maxn=120;
    const int magic_val=120;
    const int attack_times=120;
    
    int dp[magic_val][attack_times];
    
    struct node{
        int cost,dps;
    }skill[maxn];
    
    int max(int a,int b){
        return a>b?a:b;
    }
    
    int main(){
    
        //freopen("input.txt","r",stdin);
    
        int n,t,q;
        while(scanf("%d%d%d",&n,&t,&q)){
            if(n==0 && t==0 && q==0)
                break;
            memset(dp,0,sizeof(dp));
            int i,j,k,res=0;
            for(i=0;i<n;i++)
                scanf("%d%d",&skill[i].cost,&skill[i].dps);
            skill[n].cost=0;skill[n].dps=1;
            for(k=1;k<=100;k++){        //最多攻击100次  
                if(res)
                    break;
                for(i=0;i<=n;i++)
                    for(j=100;j>=skill[i].cost;j--){
                        int mag=j-skill[i].cost+t;
                        if(mag>100)
                            mag=100;
                        dp[mag][k]=max(dp[mag][k],dp[j][k-1]+skill[i].dps);
                        if(dp[mag][k]>=100)
                            res=k;
                    }
            }
            if((res-1)*q>=100)
                printf("My god\n");
            else
                printf("%d\n",res);
        }
        return 0;
    }

     

     

  • 相关阅读:
    js中return的作用
    jstl标签详解总结
    css——overflow属性用法
    oracle数据批处理
    SQL Server 2000/2005 分页SQL — 单条SQL语句
    dataset和实体类 之间的转换
    barmanager设置
    C#集合类(HashTable, Dictionary, ArrayList)与HashTable线程安全
    comboboxEdit 不能输入,只能选择
    C#在父窗口中调用子窗口的过程(无法访问已释放的对象)
  • 原文地址:https://www.cnblogs.com/jackge/p/2984523.html
Copyright © 2011-2022 走看看