|洛谷|排序|P1309 瑞士轮

http://www.luogu.org/problem/show?pid=1309#sub

第一次快排,之后用a,b记录输赢的集合,赢了的和输了的的相对排序一致,用归并排序

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define ms(i,j) memset(i,j, sizeof i);
using namespace std;
struct ps
{
	int id;
	int score;
	int w;
}ans[200005], a[200005], b[200005];//第一次没开到200005丢了30分
bool cmp(ps const &i, ps const &j)
{
	if (i.score>j.score) return true;
	else if (i.score<j.score) return false;
	else return i.id<j.id;
}
int main()
{
	int n,r,q;
	scanf("%d%d%d", &n ,&r, &q);
	for (int i=1;i<=2*n;i++) { ans[i].id = i;
	 	scanf("%d", &ans[i].score); }
	for (int i=1;i<=2*n;i++)
	 	scanf("%d", &ans[i].w);	  
	sort(ans+1, ans+1+n*2, cmp);
	for (int i=1;i<=r;i++)
	{
		int ai = 0, bi = 0;
		for (int j=1;j<=n*2;j+=2)
		{
			if (ans[j].w>ans[j+1].w)
			{
				ans[j].score++;
				b[++bi] = ans[j+1];
				a[++ai] = ans[j];
			}
			else
			{
				ans[j+1].score++;
				b[++bi] = ans[j];
				a[++ai] = ans[j+1];
			}
		}
		merge(a+1, a+n+1, b+1, b+n+1, ans+1, cmp);
	}
	printf("%d\n", ans[q].id);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值