POJ 3465Battle

题目来源:

http://poj.org/problem?id=3465

排位赛遇到的一道,直接贪心。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
typedef long long ll;
ll a[100100];
int main()
{
	ll T,n,i,j,h1,h2,x,y;
	scanf("%lld%lld%lld%lld%lld",&n,&x,&y,&h1,&h2);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	ll cnt=0,ans=0,MAX=-1;
	priority_queue<int>qq;//优先队列,数值大的先出列。 
	for(i=1;i<=n;i++)
	{
		cnt++;//表示次数
		if(h2<=cnt*x)
		{
			break;
		}
		MAX=max(MAX,cnt);
		h1-=a[i];
		qq.push(max(a[i],y));
		while(h1<=0&&!qq.empty())
		{
			h1+=qq.top();
			qq.pop();
			cnt--;
		}
	}
		if(i<=n)
		{
			printf("Win\n");
			printf("%lld",i); 
		}
		else
		{
			printf("Lose\n");
			ans=MAX*x;
			printf("%lld",ans);
		}
		return 0;
	}
发布了56 篇原创文章 · 获赞 17 · 访问量 2347

猜你喜欢

转载自blog.csdn.net/weixin_43958964/article/details/99109224
POJ
今日推荐