[SGU]114. Telecasting station

来源:互联网 发布:美工助理面试自我介绍 编辑:程序博客网 时间:2024/05/22 00:09

Analysis

    这题寻找一个在最中间的citizen输出位置就可以了,证明略(很简单的……)

Accepted Code

var    n,i,k,sump:longint;    x,p:array[1..15000] of longint;procedure sort(l,r:longint);var    i,j,mid,tmp:longint;begin    mid:=x[(l+r) shr 1];    i:=l;    j:=r;    repeat        while x[i]<mid do            inc(i);        while x[j]>mid do            dec(j);        if not (i>j) then        begin            tmp:=x[i];            x[i]:=x[j];            x[j]:=tmp;            tmp:=p[i];            p[i]:=p[j];            p[j]:=tmp;            inc(i);            dec(j);        end;    until i>j;    if i<r then        sort(i,r);    if l<j then        sort(l,j);end;begin    read(n);    sump:=0;    for i:=1 to n do    begin        read(x[i],p[i]);        sump:=sump+p[i];    end;    sort(1,n);    i:=1;    k:=0;    while k<=sump shr 1 do    begin        inc(k,p[i]);        inc(i);    end;    i:=i-1;    writeln(x[i],'.00000');end.


原创粉丝点击