科研先行(research)
输入文件:research.in
输出文件:research.out
【问题描述】
Neyc绿化破坏电信事件,给领导层造成了很大的麻烦。为避免类似事件发生,领导意识到,做任何事情,科研必须先行。为此,Neyc专门成立了研究所,对Neyc的整体建设进行研究设计。研究所计划从全国各地邀请相关专家集中研讨。因为每个地区邀请的人数不同,出于节约经费的问题,Neyc研究所希望集中讨论的时候能尽量花费较少的费用。于是,就出现了一个集中地点的选择问题。
假设被邀请参与研究人员所在的地区都在一条直线上,并知道每个地区与Neyc的距离和该地被邀请人员的数目(假设Neyc在最左端)。请你编程帮助他们确定在哪个地区集中研讨可以使所有被邀请的人员集中到该地区的费用总和最小。
【输入文件】输入文件每一行描述一个地区的信息(地区数<=5000);
对于每一行,首先是该地区被邀请的人员数目,紧跟着是这个地区相对于Neyc的距离,最后是该地区的名称。(技术人员数<=100,地区的相对距离<=10^31,地区名称长度<=20,数据保证有唯一的解)。
【输出文件】
输出文件只需一行,即研究所确定的集中研讨的地区名称。
【样例输入】
7 9289 shengyan
5 8523 beijing
3 5184 guilin
8 2213 chongqing
10 0 wuhan
【样例输出】
chongqing
====================
带权中位数+字符串的排序。
====================
type
re=record
num:longint;
dis:ansistring;
name:string;
end;
var
n:longint;
t:array[1..5000]of re;
procedure init;
begin
assign(input,'research.in');
assign(output,'research.out');
reset(input);
rewrite(output);
end;
procedure terminate;
begin
close(input); close(output);
halt;
end;
procedure qsort(s_,t_:longint);
var
i,j:longint;
x,tem:re;
begin
x:=t[s_];
i:=s_; j:=t_;
repeat
while (i<j) and (((length(x.dis)=length(t[j].dis)) and (x.dis<=t[j].dis))or(length(x.dis)<length(t[j].dis))) do dec(j);
if i<j then begin tem:=t[j]; t[j]:=t[i]; t[i]:=tem; end;
while (i<j) and (((length(x.dis)=length(t[i].dis)) and (x.dis>=t[i].dis))or(length(x.dis)>length(t[i].dis))) do inc(i);
if i<j then begin tem:=t[i]; t[i]:=t[j]; t[j]:=tem; end;
until i=j;
t[i]:=x;
inc(i); dec(j);
if s_<j then qsort(s_,j);
if i<t_ then qsort(i,t_);
end;
procedure main;
var
ch:char;
i,tot,tot_:longint;
begin
n:=0;
tot:=0;
while not eof do
begin
inc(n);
read(t[n].num);
tot:=tot+t[n].num;
t[n].name:='';
t[n].dis:='';
read(ch);
read(ch);
while ch<>' 'do
begin
t[n].dis:=t[n].dis+ch;
read(ch);
end;
while not eoln do
begin
read(ch);
t[n].name:=t[n].name+ch;
end;
readln;
end;
{for i:=1 to n do
begin
writeln(t[i].num,' ',t[i].dis,' ',t[i].name)
end;}
qsort(1,n);
tot:=tot div 2;
tot_:=0;
for i:=1 to n do
begin
tot_:=tot_+t[i].num;
if tot_>tot then break;
end;
writeln(t[i].name);
{for i:=1 to n do
begin
writeln(t[i].num,' ',t[i].dis,' ',t[i].name)
end;}
end;
begin
init;
main;
terminate;
end.