其他分享
首页 > 其他分享> > codeforces 1154E Two Teams

codeforces 1154E Two Teams

作者:互联网

题目链接:Two Teams

题意:有两个教练,team=1和team=2,两个教练分别要挑人进入自己的集训队。每次挑分数最高的以及他两边最多k个人进队伍。问挑完以后哪些人进了1队哪些人进了2队

思路:在网上看到了大佬们用c++的STL里的list进行操作,即可

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<set>
#include<vector>
#include<memory.h>
#include<list>
using namespace std;
const int maxn = 2 * 100000 + 10;
typedef long long ll;
list<pair<int, int> > L;
list<pair<int, int> >::iterator ite[maxn];
pair<int, int> a[maxn];
bool vis[maxn];
int ans[maxn];
int n, k;
int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> k;
	int team = 1;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i].first;
		a[i].second = i;
		L.push_back(a[i]);
		ite[i] = --L.end();
	}
	sort(a + 1, a + 1 + n);
	for (int i = n; i >= 1; i--)
	{
		int id = a[i].second;
		if (vis[id])
			continue;
		list<pair<int, int> >::iterator l = ite[id], r = ite[id];
		for (int i = 1; i <= k; i++)
		{
			if (l != L.begin())
				l--;
			if (r != --L.end())
				r++;
		}
		r++;
		while (l != r)
		{
			ans[l->second] = team;
			vis[l->second] = true;
			l = L.erase(l);
		}
		team = 3 - team;
	}
	for (int i = 1; i <= n; i++)
		cout << ans[i];
	return 0;
}

 

 

标签:int,ite,codeforces,Two,Teams,maxn,team,include,id
来源: https://blog.csdn.net/okimaru/article/details/90139985