NOIP2011T3 瑞士轮

【题目来源】

http://codevs.cn/problem/1132/

[SAMPLE INPUT]

2 4 2
7 6 6 7
10 5 20 15 

[SAMPLE OUTPUT]

1

  

#include<cstdio>
#include<algorithm>
using namespace std;
int n,r,q;
struct node{int no,f,p; }a[200010],w[100010],l[100010];
bool cmp(node a,node b){return a.f==b.f?a.no<b.no:a.f>b.f;}
int main(){
    scanf("%d%d%d",&n,&r,&q); n*=2;
    for(int i=1;i<=n;++i) scanf("%d",&a[i].f),a[i].no=i;
    for(int i=1;i<=n;++i) scanf("%d",&a[i].p);
    sort(a+1,a+1+n,cmp);
    while(r--){
        int wi=0,li=0;
        for(int i=1;i<=n;i+=2)
            if(a[i].p<a[i+1].p) w[++wi]=a[i+1],l[++li]=a[i];
            else l[++li]=a[i+1],w[++wi]=a[i];
        for(int i=1;i<=n/2;i++)w[i].f++;
        wi=li=1; int ai=0;
        while(wi<=n/2 && li<=n/2) a[++ai]=cmp(w[wi],l[li])?w[wi++]:l[li++];
        if(wi>n/2) while (li<=n/2) a[++ai]=l[li++];
        else while(wi<=n/2) a[++ai]=w[wi++];
    }
    printf("%d\n",a[q].no);
    return 0;
}

  

 

#include<cstdio>
#include<algorithm>
using namespace std;
int n,r,q;
struct node{ int s,p,ii; }a[200010],w[100010],l[100010];
bool cmp(node a,node b){
    if (a.s==b.s) return a.ii<b.ii;
    return a.s>b.s;
}
int main(){
    scanf("%d%d%d",&n,&r,&q); n*=2;
    for(int i=1;i<=n;++i) scanf("%d",&a[i].s),a[i].ii=i;
    for(int i=1;i<=n;++i) scanf("%d",&a[i].p);
    sort(a+1,a+1+n,cmp);
    while(r--){
        int wi=0,li=0;
        for(int i=1;i<=n;i+=2)
            if(a[i].p<a[i+1].p) w[++wi]=a[i+1],l[++li]=a[i];
            else l[++li]=a[i+1],w[++wi]=a[i];
        for(int i=1;i<=n/2;i++)w[i].s++;
        wi=li=1; int ai=0;
        while(wi<=n/2 && li<=n/2) a[++ai]=cmp(w[wi],l[li])?w[wi++]:l[li++];
        if(wi>n/2) while (li<=n/2) a[++ai]=l[li++];
        else while(wi<=n/2) a[++ai]=w[wi++];
    }
    printf("%d\n",a[q].ii);
    return 0;
}

  

 

//100分代码

#include<cstdio>
#include<algorithm>
using namespace std;
int n,r,q,i,j,ji;
struct node{ int s,p,ii; }a[200010],w[100010],l[100010];
bool cmp(node a,node b){
    if (a.s==b.s) return a.ii<b.ii;
    return a.s>b.s;
}
int main(){
    freopen("swiss.in","r",stdin); 
    freopen("swiss.out","w",stdout); 
    scanf("%d%d%d",&n,&r,&q); n*=2;
    for(i=1;i<=n;++i) scanf("%d",&a[i].s),a[i].ii=i;
    for(j=1;j<=n;++j) scanf("%d",&a[j].p);
    sort(a+1,a+1+n,cmp);
    for(ji=1;ji<=r;ji++){
        int wi=1,lo=1;
        for(i=1;i<=n;i+=2)
            if(a[i].p<a[i+1].p) w[wi++]=a[i+1],l[lo++]=a[i];
            else if (a[i].p>a[i+1].p)l[lo++]=a[i+1],w[wi++]=a[i];
        wi--;lo--;
        for(i=1;i<=n/2;i++)w[i].s++;
        int x=1,y=1;
        i=0;
        while(x<=n/2 && y<=n/2){
            if(w[x].s>l[y].s) a[++i]=w[x++];
            if(w[x].s<l[y].s) a[++i]=l[y++];
            if(w[x].s==l[y].s&&w[x].ii>l[y].ii) a[++i]=l[y++];
            if(w[x].s==l[y].s&&w[x].ii<l[y].ii) a[++i]=w[x++];
        }
        if(x>n/2) while (y<=n/2) a[++i]=l[y++];
        else while(x<=n/2) a[++i]=w[x++];
    }
    printf("%d\n",a[q].ii);
    fclose(stdin); fclose(stdout);
    return 0;
}

  

//90分代码,一组数据超时

#include<cstdio>
#include<algorithm>
using namespace std;
const int N=200000+10;
int n,q,r,w[N];
struct D{
    int s,num;
    bool operator < (D x) const {return x.s==s?x.num>num:x.s<s;};
}data[N];

int main(){
    scanf("%d%d%d",&n,&r,&q);
    n*=2;
    for(int i=0;i<n;i++){scanf("%d",&data[i].s); data[i].num=i;}
    for(int i=0;i<n;i++)scanf("%d",&w[i]);
    for(int i=0;i<r;i++){
        sort(data,data+n);
        for(int j=0;j<n;j+=2){
            if(w[data[j].num]>w[data[j+1].num])data[j].s+=1;
            else data[j+1].s+=1;
        }
    }sort(data,data+n);
    printf("%d\n",data[q-1].num+1);
    return 0;
}

  

 

const
    MAX=100050;
type
    NODE=record
        no,sl,fs:longint;
    end;
var
    a:array[0..2*MAX] of NODE;
    b,c:array[0..MAX] of NODE;
    i,j,N,N2,R,Q:longint;

procedure Qsort(l,r:longint);
var i,j,k1,k2:longint;
begin
    i:=l; j:=r;
    k1:=a[(i+j) shr 1].fs;
    k2:=a[(i+j) shr 1].no;
    repeat
        while (a[i].fs>k1) or (a[i].fs=k1) and (a[i].no<k2) do inc(i);
        while (a[j].fs<k1) or (a[j].fs=k1) and (a[j].no>k2) do dec(j);
        if i<=j then
        begin
            a[MAX]:=a[i]; a[i]:=a[j]; a[j]:=a[MAX];
            inc(i); dec(j);
        end;
    until i>j;
    if i<r then Qsort(i,r);
    if l<j then Qsort(l,j);
end;

procedure Fight;
var i,j,k:longint;
begin
    for i:=0 to N-1 do
    begin
        if(a[2*i].sl>a[2*i+1].sl) then
        begin
            inc(a[2*i].fs); b[i]:=a[2*i]; c[i]:=a[2*i+1];
        end
        else
        begin
            inc(a[2*i+1].fs); b[i]:=a[2*i+1]; c[i]:=a[2*i];
        end;
    end;
    i:=0;j:=0;k:=0;
    while(j<N)and(k<N) do
        if((b[j].fs>c[k].fs)or(b[j].fs=c[k].fs)and(b[j].no<c[k].no)) then
        begin
            a[i]:=b[j]; inc(j); inc(i);
        end
        else
        begin
            a[i]:=c[k]; inc(k); inc(i);
        end;
    while(j<N) do begin a[i]:=b[j]; inc(j); inc(i); end;
    while(k<N) do begin a[i]:=c[k]; inc(k); inc(i); end;
end;

begin
    readln(N,R,Q); N2:=N*2;
    for i:=0 to N2-1 do begin a[i].no:=i+1; read(a[i].fs); end;
    for i:=0 to N2-1 do read(a[i].sl);
    Qsort(0,N2-1);
    for i:=1 to R do Fight;
    writeln(a[Q-1].no);
end.

 

posted @ 2013-10-24 00:09  qilinart  阅读(245)  评论(0编辑  收藏  举报