【题外话:这道题吧……说实话我不太喜欢……因为卡快排。】
题目不贴了,就是给你一个赛制,然后各个选手的初始得分和能力值,问你进行R轮比赛之后第Q名的编号是多少(这个编号读进来就要算OYZ,初始快排的时候也要注意。)
我是用的比较常规的方法,每次扫描整个序列,计算胜者和负者,分入两个数组,然后把这两个数组归并回原来的序列里(因为这两个序列都已经有序,所以可以免去排序直接合并),题目中要求编号小的排在前面,因为归并是稳定排序所以不需要担心这些。
其实本质来说就是个讲究技巧的模拟吧?
下贴代码,风格照样丑。
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
ifstream fin("swiss.in");
ofstream fout("swiss.out");
struct per
{
int fs;
int nl;
int bh;
};
per player[200005];
int Rs=0,ls=0,gz=0;
per winner[100005]={0},loser[100005]={0};
void Heib();
bool px(per a,per b);
int main(void)
{
fin>>Rs>>ls>>gz;
Rs*=2;
for(int i=1;i<=Rs;i++)
{
fin>>player[i].fs;
player[i].bh=i;
}
for(int i=1;i<=Rs;i++)fin>>player[i].nl;
sort(player+1,player+Rs+1,px);
for(int i=1;i<=ls;i++)
{
for(int j=1;j<=Rs;j++)
{
if(j%2==0)
{
if(player[j].bh==127||player[j-1].bh==127)
{
}
if(player[j].nl>player[j-1].nl)
{
winner[j/2].bh=player[j].bh;
winner[j/2].fs=player[j].fs+1;
winner[j/2].nl=player[j].nl;
loser[j/2].bh=player[j-1].bh;
loser[j/2].fs=player[j-1].fs;
loser[j/2].nl=player[j-1].nl;
}
else
{
winner[j/2].bh=player[j-1].bh;
winner[j/2].fs=player[j-1].fs+1;
winner[j/2].nl=player[j-1].nl;
loser[j/2].bh=player[j].bh;
loser[j/2].fs=player[j].fs;
loser[j/2].nl=player[j].nl;
}
}
}
Heib();
}
fout<<player[gz].bh;
return 0;
}
bool px(per a,per b)
{
if(a.fs>b.fs)return 1;
if(a.fs==b.fs&&a.bh<b.bh)return 1;
if(a.fs==b.fs&&a.bh>b.bh)return 0;
return 0;
}
void Heib()
{
int lf=1,rt=1,zz=1;
while(lf<=Rs/2&&rt<=Rs/2)
{
if(winner[lf].fs>loser[rt].fs||(winner[lf].fs==loser[rt].fs&&winner[lf].bh<loser[rt].bh))
{
player[zz].bh=winner[lf].bh;
player[zz].fs=winner[lf].fs;
player[zz].nl=winner[lf].nl;
zz++;
lf++;
}
if(winner[lf].fs<loser[rt].fs||(winner[lf].fs==loser[rt].fs&&winner[lf].bh>loser[rt].bh))
{
player[zz].bh=loser[rt].bh;
player[zz].fs=loser[rt].fs;
player[zz].nl=loser[rt].nl;
zz++;
rt++;
}
}
while(lf<=Rs/2||rt<=Rs/2)
{
if(lf<=Rs/2)
{
player[zz].bh=winner[lf].bh;
player[zz].fs=winner[lf].fs;
player[zz].nl=winner[lf].nl;
lf++;
}
if(rt<=Rs/2)
{
player[zz].bh=loser[rt].bh;
player[zz].fs=loser[rt].fs;
player[zz].nl=loser[rt].nl;
rt++;
}
zz++;
}
return;
}
【题外话2:其实两篇解题报告之间我还A了几道题,不过都太简单或者太恶心到我不想写题解……OYZ】
【题外话3:这里是个准初三狗,一开学成了初三狗之后估计就不会太快更新了……】