POJ3465-Battle

来源:互联网 发布:斗牛开挂软件 编辑:程序博客网 时间:2024/04/30 15:40

Battle

You’re Zhu Rengong, a formidable hero. After a number of challenging missions, you are finally facing the final Boss – a black dragon called Heilong. Due to his overwhelming power, you have to plan your actions carefully.

You have H1 hit points (HP) at the beginning of the battle, and Heilong has H2. Heilong attacks you each time you do an action, and deal Ai points of damage in the i-th round. You have three kinds of actions.

Attack. You attack Heilong, and do x points of damage.
Defend. You focus on avoiding the attack of Heilong. This action nullifies Heilong’s attack in this round.
Heal. You heal yourself, adding y hit points to yourself. There is no upper bound on your HP.
If anyone’s HP drop below or equal to 0, he dies. If you can’t kill the dragon within N rounds, you will also die. So you need to know how many rounds you need to kill the black dragon. If you cannot kill him, you will have to calculate the maximal damage you can do on Heilong.

Input
The first line contains five integers, N, x, y, H1, H2. 1 ≤ N ≤ 105, 1 ≤ x,y ≤ 104, 1 ≤ H1,H2 ≤ 109. Then follow N lines, the ith line contains one integer Ai-1. 1 ≤ Ai-1 ≤ 104.

Output
If you can kill Heilong, the first line of your output should be “Win”. Otherwise “Lose”.
The second line contains the number of rounds you need to kill Heilong if the first line is “Win”, or the maximal damage you can do if the first line is “Lose”.

Sample Input
Sample Input 1
4 1 1 3 3
1
10
1
10

Sample Input 2
4 1 1000 1 4
1
10
1
1

Sample Output
Sample Output 1
Win
4

Sample Output 2
Lose
3

Hint
In Sample 1, you have to defend in the 2nd round, othewise you will die.
In Sample 2, you heal yourself in the first round, and keep attacking until N rounds expires.

题目大意: 你开始有H1滴血,敌人有H2滴血,你有三种技能:
(1)攻击,造成对手x点伤害
(2)防御,对手攻击无效
(3)补血,补回自己y点血
对手每回合对你进行攻击,伤害为a[i]
问你能否在N轮之前战胜敌人,若能求出战胜时的轮数,否则输出你能对敌人造成的最大伤害。
解题思路: 为能在N轮之前战胜敌人,贪心的想法是尽量攻击,若自己血量小于等于0,则从上面的回合中撤销一次攻击,这次撤销能补回最多的血量(防御相当于补回a[i]点血),所以用优先队列。
注意点: 若失败则要在模拟中记录能攻击的最多的轮数。

#include<iostream>#include<cstdio>#include<vector>#include<queue>using namespace std;const int MAXN=1e5+5;priority_queue<int> pq;int a[MAXN];int main(){    ios::sync_with_stdio(false);    int n,x,y,h1,h2;    while(cin>>n>>x>>y>>h1>>h2)    {        while(!pq.empty()) pq.pop();        for(int i=1;i<=n;i++)            cin>>a[i];        int cnt=0;        bool flag=false;        int round=0;        int maxcnt=0;        for(int i=1;i<=n;i++)        {            cnt++;            if(cnt*x>=h2)            {                flag=true;                round=i;                break;            }            maxcnt=max(cnt,maxcnt);            h1-=a[i];            pq.push(max(a[i],y));            while(h1<=0&&!pq.empty())            {                h1+=pq.top();                pq.pop();                cnt--;            }        }        if(flag)        {            cout<<"Win"<<endl;            cout<<round<<endl;        }else        {            cout<<"Lose"<<endl;            cout<<maxcnt*x<<endl;        }    }    return 0;}