codeforces 1056 C. Pick Heroes(贪心)

题目:http://codeforces.com/contest/1056/problem/C

题意:(交互题)
有2n个英雄 每个英雄有对应战斗力
有些英雄是counter英雄 (互相克制)一方必须选一个
最后选择最优的英雄组合

思路:毫无疑问是贪心,一开始我就想直接把所有英雄战斗力排序,从大选到小就好了,对方输出克制中英雄的一个,我就输出对应的,结果wa7,没想到对方必须选克制英雄这一条件,后来看了下题解,
还是不够贪 应该先考虑克制英雄里面最大的,因为双方必须从2个中选一个,一定要优先考虑克制中最大的,再选择剩下里面最大的。

#include<bits/stdc++.h>
#define fi first
#define se second
#define FOR(a) for(int i=0;i<a;i++)
#define sc(a) scanf("%d",&a)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<P, int> LP;
const ll inf = 1e17 + 10;
const int N = 3e5 + 10;
const ll mod = 998244353;

map<string, int>ml;



ll b[N], vis[N], po[N],num[N], t, n, m, x, y, k, a[N];
ll ex, ey, cnt, ans, sum, flag;
ll dist[N];
ll dp[N];

vector<int> v[N];
map<int,int> mp;
priority_queue<P> q;
priority_queue<P> tq;


int main()
{
	ios::sync_with_stdio ( false );
	cin.tie ( 0 );

	cin>>n>>m;
	for(int i=1;i<=2*n;i++)
	{
		cin>>a[i];
		q.push(make_pair(a[i],i));
	}
	for(int i=1;i<=m;i++)
	{
		cin>>x>>y;
		if(a[x]>a[y])
		{
			tq.push(make_pair(a[x],x));
		}
		else tq.push(make_pair(a[y],y));
		mp[x]=y;
		mp[y]=x;
	}
	t=m;
	n=n*2;
	cin>>k;
	int flag=0;
	if(k==2)
	{
		while(n)
		{
			cin>>x;
			n--;
			vis[x]=1;
			flag=0;
			if(mp[x]&&!vis[mp[x]])
			{
				cout<<mp[x]<<endl;
				t--;
				vis[mp[x]]=1;
				n--;
				flag=1;
			}
			if(n==0) break;
			if(t&&flag==0)
			{
				while(vis[tq.top().se])tq.pop();
				cout<<tq.top().se<<endl;
				vis[tq.top().se]=1;
				t--;
				n--;
			}
			else if(!t&&flag==0)
			{
				while(vis[q.top().se])q.pop();
				cout<<q.top().se<<endl;
				n--;
				vis[q.top().se]=1;
				q.pop();
			}
		}
	}
	else
	{
		while(n)
		{
			//show2('n',q.top().se);
			if(t&&flag==0)
			{
				while(vis[tq.top().se])tq.pop();
				cout<<tq.top().se<<endl;
				vis[tq.top().se]=1;
				t--;
				n--;
			}
			else if(!t&&flag==0)
			{
				while(vis[q.top().se])q.pop();
				cout<<q.top().se<<endl;
				n--;
				vis[q.top().se]=1;
				q.pop();
			}
			if(n==0) break;
			//show2('t',t)
			flag=0;
			cin>>x;
			n--;
			vis[x]=1;
			if(mp[x]&&!vis[mp[x]])
			{
				cout<<mp[x]<<endl;
				t--;
				vis[mp[x]]=1;
				n--;
				flag=1;
			}

		}
	}






}

猜你喜欢

转载自blog.csdn.net/weixin_42640692/article/details/86516695