Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
郁闷了,各种数据都能过,就是错var ans,i,j,k,l,m,n:Longint; a,b:array[0..1001] of longint; f,g:array[0..1001,0..1001] of longint; procedure qsort1(l,r:longint); var i,j,x:longint; begin i:=l;j:=r;x:=a[(i+j) div 2]; repeat while a[i]>x do inc(i); while a[j]<x do dec(j); if i<=j then begin k:=a[i];a[i]:=a[j];a[j]:=k; inc(i);dec(j); end; until i>j; if i<r then qsort1(i,r); if l<j then qsort1(l,j); end; procedure qsort2(l,r:longint); var i,j,x:Longint; begin i:=l;j:=r;x:=b[(i+j) div 2]; repeat while b[i]>x do inc(i); while b[j]<x do dec(j); if i<=j then begin k:=b[i];b[i]:=b[j];b[j]:=k; inc(i);dec(j); end; until i>j; if i<r then qsort2(i,r); if l<j then qsort2(l,j); end; procedure init; var i,j:longint; begin readln(n); if n=0 then halt; for i:=1 to n do read(a[i]); for i:=1 to n do read(b[i]); end; function max(x,y:longint):longint; begin if x>y then exit(x); exit(y); end; procedure main; var i,j:Longint; begin qsort1(1,n); qsort2(1,n); for i:=1 to n do for j:=1 to n do begin if a[i]>b[j] then g[i,j]:=400; if a[i]=b[j] then g[i,j]:=200; if a[i]<b[j] then g[i,j]:=0; end; for i:=1 to n do for j:=1 to i do f[i,j]:=max(f[i-1,j]+g[n-i+j+1,i],f[i-1,j-1]+g[j,i]); end; procedure print; var i,j:Longint; begin ans:=-2000000; for i:=1 to n do if f[n,i]>ans then ans:=f[n,i]; writeln(ans-n*200); end; begin assign(input,'2287.in');reset(input); while not eof do begin init; if n=0 then halt; main; print; end; close(input); end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator