记录编号 |
33744 |
评测结果 |
TTTTTTTTTA |
题目名称 |
抗震救灾 |
最终得分 |
10 |
用户昵称 |
reamb |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
9.099 s |
提交时间 |
2011-11-11 18:53:37 |
内存使用 |
8.30 MiB |
显示代码纯文本
program savez;
var
p:array[1..5000]of longint;
d,ming:array[1..5000]of string;
jilu,ans,s,people,z,cha,price:string;
b,c,a:array[1..1000000]of integer;
t,weizhi,l,i,j,lx,ly:longint;
procedure swap(var a,b:string);
var
c:string;
begin
c:=a;
a:=b;
b:=c
end;
function max(a,b:longint):longint;
begin
if a>b then
exit(a)
else
exit(b)
end;
function mo(x,y:ansistring):ansistring;
var
i,j:longint;
begin
s:='';
lx:=length(x);
ly:=length(y);
fillchar(a,sizeof(a),0);
fillchar(b,sizeof(b),0);
for i:=1 to lx+ly do
c[i]:=0;
for i:=lx downto 1 do
a[lx-i+1]:=ord(x[i])-ord('0');
for i:=ly downto 1 do
b[ly-i+1]:=ord(y[i])-ord('0');
for i:=1 to lx do
for j:=1 to ly do
begin
c[i+j-1]:=c[i+j-1]+a[i]*b[j];
c[i+j]:=c[i+j]+c[i+j-1]div 10;
c[i+j-1]:=c[i+j-1]mod 10
end;
if c[lx+ly]>0 then
l:=lx+ly
else
l:=lx+ly-1;
for i:=l downto 1 do
s:=s+chr(ord('0')+c[i]);
exit(s)
end;
function add(x,y:string):string;
var
i,j:longint;
begin
s:='';
lx:=length(x);
ly:=length(y);
fillchar(a,sizeof(a),0);
fillchar(b,sizeof(b),0);
for i:=1 to max(lx,ly)+1 do
c[i]:=0;
for i:=lx downto 1 do
a[lx-i+1]:=ord(x[i])-ord('0');
for i:=ly downto 1 do
b[ly-i+1]:=ord(y[i])-ord('0');
for i:=1 to max(lx,ly) do
begin
c[i]:=c[i]+(a[i]+b[i])mod 10;
c[i+1]:=c[i+1]+(a[i]+b[i])div 10
end;
if c[max(lx,ly)+1]>0 then
l:=max(lx,ly)+1
else
l:=max(lx,ly);
for i:=l downto 1 do
s:=s+chr(ord('0')+c[i]);
exit(s)
end;
function jian(x,y:string):string;
var
i,j:longint;
begin
s:='';
if x<y then
swap(x,y);
lx:=length(x);
ly:=length(y);
fillchar(a,sizeof(a),0);
fillchar(b,sizeof(b),0);
for i:=lx downto 1 do
a[lx-i+1]:=ord(x[i])-ord('0');
for i:=ly downto 1 do
b[ly-i+1]:=ord(y[i])-ord('0');
for i:=1 to lx do
begin
if a[i]<b[i] then
begin
dec(a[i+1]);
a[i]:=a[i]+10
end;
c[i]:=a[i]-b[i]
end;
l:=lx;
while c[l]=0 do
dec(l);
for i:=l downto 1 do
s:=s+chr(ord('0')+c[i]);
exit(s)
end;
begin
assign (input,'savez.in');
reset (input);
assign (output,'savez.out');
rewrite (output);
repeat
inc(t);
read (p[t]);
readln (s);
delete(s,1,1);
weizhi:=pos(' ',s);
d[t]:=copy(s,1,weizhi-1);
ming[t]:=copy(s,weizhi+1,length(s)-weizhi)
until eof;
ans:='9999999999999999999999999999999999999999999999999999999999';
for i:=1 to t do
begin
z:='';
for j:=1 to t do
if i<>j then
begin
str(p[j],people);
cha:=jian(d[i],d[j]);
price:=mo(people,cha);
z:=add(z,price)
end;
if z<ans then
begin
ans:=z;
jilu:=ming[i]
end
end;
writeln (jilu);
close (input);
close (output)
end.