1 条题解
-
0
C++ :
#include<iostream> #include<algorithm> using namespace std; const int N = 100005; struct person{ int id,score,power; }; person a[2*N],win[N],lose[N]; bool comp(const person &x,const person &y){ if (x.score!=y.score) return x.score>y.score; return x.id<y.id; } void swiss(int n){ int i,j,k; for (k=i=j=1; k<=n; k++) if (a[2*k-1].power>a[2*k].power) a[2*k-1].score++,win[i++]=a[2*k-1],lose[j++]=a[2*k]; else a[2*k].score++,win[i++]=a[2*k],lose[j++]=a[2*k-1]; for (k=i=j=1; i<=n&&j<=n; k++) if (comp(win[i],lose[j])) a[k]=win[i++]; else a[k]=lose[j++]; while (i<=n) a[k++]=win[i++]; while (j<=n) a[k++]=lose[j++]; } int main(){ int n,r,q; cin>>n>>r>>q; for (int i=1; i<=2*n; i++){ cin>>a[i].score; a[i].id=i; } for (int i=1; i<=2*n; i++) cin>>a[i].power; sort(a+1,a+2*n+1,comp); for (int i=1; i<=r; i++) swiss(n); cout<<a[q].id<<endl; return 0; }
Pascal :
var n,s,q,i,j,t,x:longint; a,c,p,b,d,e,f,h,g:array[0..500000]of longint; procedure qsort(l,r:longint); var i,j,mid,mid1,t:longint; begin i:=l;j:=r; mid:=a[(i+j)div 2]; mid1:=p[(i+j)div 2]; while i<=j do begin while (a[i]>mid)or(a[i]=mid)and(p[i]<mid1)do inc(i); while (a[j]<mid)or(a[j]=mid)and(p[j]>mid1)do dec(j); if i<=j then begin t:=a[i];a[i]:=a[j];a[j]:=t; t:=c[i];c[i]:=c[j];c[j]:=t; t:=p[i];p[i]:=p[j];p[j]:=t; inc(i);dec(j); end; end; if l<j then qsort(l,j); if i<r then qsort(i,r); end; procedure marge; var i,j,k:longint; begin i:=1;j:=n+1;k:=1; while (i<=n)and(j<=n*2) do if (f[j]>f[i])or(f[j]=f[i])and(g[j]<g[i]) then begin b[k]:=f[j];d[k]:=h[j];e[k]:=g[j];inc(j);inc(k);end else begin b[k]:=f[i];d[k]:=h[i];e[k]:=g[i];inc(k);inc(i);end; while i<=n do begin b[k]:=f[i];d[k]:=h[i];e[k]:=g[i];inc(k);inc(i);end; while j<=n*2 do begin b[k]:=f[j];d[k]:=h[j];e[k]:=g[j];inc(k);inc(j);end; for i:=1 to n*2 do begin f[i]:=b[i];h[i]:=d[i];g[i]:=e[i];end; end; begin readln(n,s,q); for i:=1 to n*2 do read(a[i]); for i:=1 to n*2 do begin read(c[i]); p[i]:=i; end; qsort(1,n*2); for i:=1 to s do begin for j:=1 to n do begin x:=j*2; if c[x-1]>c[x] then begin inc(a[x-1]); f[j]:=a[x-1];f[j+n]:=a[x]; g[j]:=p[x-1];g[j+n]:=p[x]; h[j]:=c[x-1];h[j+n]:=c[x]; end else begin inc(a[x]); f[j]:=a[x];f[j+n]:=a[x-1]; g[j]:=p[x];g[j+n]:=p[x-1]; h[j]:=c[x];h[j+n]:=c[x-1]; end; end; marge; for j:=1 to n*2 do begin a[j]:=f[j];p[j]:=g[j];c[j]:=h[j];end; end; writeln(p[q]); end.
- 1
信息
- ID
- 286
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 10
- 标签
- 递交数
- 1
- 已通过
- 0
- 上传者