您的位置:首页 > 其它

【模拟】Vijos P1771 瑞士轮 (NOIP2011普及组第三题)

2016-03-31 23:20 555 查看
题目链接:

  https://vijos.org/p/1771

题目大意:

  给定2N个人(N<=100,000)和其初始分数、能力值(能力两两不同),比赛M次(M<=50),每次PK都是按分数排序后第1和第2比,第3和第4比....能力高的获胜,问比M次后第Q个人是谁。

题目思路:

  【模拟】

  略加思索,我们不难发现,每次比赛获胜的人和失败的人分别组成了两个按分数递减的队列。

  于是一开始快排一下,接着可以按照归并排序的思路,每次比完将获胜的人和失败的人合并。时间复杂度就降到O(N*M)了。

  (一开始就随手写了个快排m次的暴力程序,丢上去只有70分,只好好好写代码了)

//
//by coolxxx
//
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) (a)*(a)
#define swap(a,b) (a)^=(b),(b)^=(a),(a)^=(b)
#define eps 1e-8
#define MAX 0x7f7f7f7f
#define INF 20000
#define PI 3.1415926535897
#define N 100004
using namespace std;
int n,m,lll,ans,cas;
struct xxx
{
int num,s,p;
}a[N<<1],w
,l
;
bool cmp(xxx aa,xxx bb)
{
if(aa.s!=bb.s)return aa.s>bb.s;
return aa.num<bb.num;
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
while(~scanf("%d",&n) && n)
{
scanf("%d%d",&m,&cas);
n<<=1;
for(i=1;i<=n;i++)
{
a[i].num=i;
scanf("%d",&a[i].s);
}
for(i=1;i<=n;i++)
scanf("%d",&a[i].p);
sort(a+1,a+1+n,cmp);
w[(n>>1)+1].s=l[(n>>1)+1].s=-MAX;
for(i=1;i<=m;i++,lll=0)
{
for(j=1;j<=n;j+=2)
{
if(a[j].p>a[j+1].p)
{
a[j].s++;
w[++lll]=a[j];
l[lll]=a[j+1];
}
else
{
a[j+1].s++;
w[++lll]=a[j+1];
l[lll]=a[j];
}
}
for(j=1,k=1;j<=(n>>1)+1 && k<=(n>>1)+1;)
if(w[j].s>l[k].s || (w[j].s==l[k].s && w[j].num<l[k].num))
a[j+k-1]=w[j++];
else
a[j+k-1]=l[k++];
}
printf("%d\n",a[cas].num);
}
return 0;
}

/*
//

//
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: