Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这是什么问题

Posted by youlandaier at 2011-09-25 21:40:58 on Problem 2454
var
        n,sum1,sum2,dt,ddt:longint;
        a,b:array[0..10000] of longint;

procedure qs(l,r:longint);
var
        i,j,k,t:longint;
begin
        i:=l;j:=r;k:=a[(i+j) >> 1];
        repeat
        while a[i]>k do inc(i);
        while a[j]<k do dec(j);
        if i<=j then
        begin
                t:=a[i];a[i]:=a[j];a[j]:=t;
                t:=b[i];b[i]:=b[j];b[j]:=t;
                inc(i);dec(j);
        end;
        until i>j;
        if i<r then qs(i,r);
        if j>l then qs(l,j);
end;


procedure init;
var
        i:longint;
begin
        randomize;
        readln(n);
        for i:=1 to 3*n do
        read(a[i]);
        for i:=1 to 3*n do
        b[i]:=i;
        qs(1,n*3);


end;

procedure work;
var
        i,j,k,t:longint;
begin
        for i:=1 to n do
        inc(sum1,a[i]);
        for i:=n+1 to n*2 do
        inc(sum2,a[i]);
        ddt:=(n >> 1)*1000;
        while true do
        begin
                i:=random(n)+1;
                j:=random(n)+n+1;
                t:=a[i];a[i]:=a[j];a[j]:=t;
                t:=b[i];b[i]:=b[j];b[j]:=t;
                dt:=a[i]-a[j];
                sum2:=sum2-dt;
                sum1:=sum1+dt;
                if (sum2>ddt) and (sum1>ddt) then
                begin
                        for k:=1 to n*3 do
                        writeln(b[k]);
                        halt;
                end;
        end;

end;

Begin
        init;

        work;

End.
随机化的程序,wa啊。。。

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator