比赛 20091026 评测结果 EEEEEEEEEE
题目名称 抢修道路 最终得分 0
用户昵称 Achilles 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-10-26 20:47:57
显示代码纯文本
program savez;
type
  gj=array[0..200]of integer;
var
  s,pla:string;
  i,j,n,code:integer;
  t,min,ans:gj;
  sz:array[1..5000]of record
    num:integer;
    g:gj;
    p:string;
  end;
function dx(s1,s2:gj):boolean;
var
  i:integer;
begin
  if s1[0]>s2[0] then dx:=true else begin
    if s2[0]>s1[0] then dx:=false else begin
      dx:=false;
      for i:=s1[0] downto 1 do
      begin
        if s1[i]>s2[i] then begin
          dx:=true;
          break;
        end;
        if s1[i]<s2[i] then break;
      end;
    end;
  end;
end;
procedure jian(s1,s2:gj);
var
  i:integer;
begin
  t:=s1;
  for i:=1 to s1[0] do
  begin
    t[i]:=t[i]-s2[i];
    if t[i]<0 then begin
      t[i]:=t[i]+10;
      t[i+1]:=t[i+1]-1;
    end;
  end;
  while t[t[0]]=0 do
    t[0]:=t[0]-1;
end;
procedure cheng(var s1:gj;num:integer);
var
  i,jw:integer;
begin
  jw:=0;
  for i:=1 to s1[0]+1 do
  begin
    s1[i]:=s1[i]*num+jw;
    jw:=s1[i] div 10;
    s1[i]:=s1[i]mod 10;
  end;
  while s1[s1[0]]>9 do
  begin
    s1[s1[0]+1]:=s1[s1[0]+1]+s1[s1[0]]div 10;
    s1[s1[0]]:=s1[s1[0]]mod 10;
    s1[0]:=s1[0]+1;
  end;
  while s1[s1[0]+1]>0 do
    s1[0]:=s1[0]+1;
end;
procedure jia(s1:gj);
var
  i:integer;
begin
  for i:=1 to s1[0] do
  begin
    min[i]:=min[i]+s1[i];
    if min[i]>9 then begin
      min[i+1]:=min[i+1]+min[i]div 10;
      min[i]:=min[i] mod 10;
    end;
  end;
  min[0]:=s1[0];
  while min[min[0]]>9 do
  begin
    min[min[0]+1]:=min[min[0]+1]+min[min[0]]div 10;
    min[min[0]]:=min[min[0]]mod 10;
    min[0]:=min[0]+1;
  end;
  while min[min[0]+1]>0 do
    min[0]:=min[0]+1;
end;
begin
  fillchar(sz,sizeof(sz),0);
  assign(input,'savez.in');
  assign(output,'savez.out');
  reset(input);
  rewrite(output);
  n:=0;
  while not(eof) do
  begin
    readln(s);
    n:=n+1;
    for i:=1 to length(s) do
    begin
      if s[i]=' ' then begin
        val(copy(s,1,i-1),sz[n].num,code);
        delete(s,1,i);
        break;
      end;
    end;
    for i:=1 to length(s) do
    begin
      if s[i]=' ' then begin
        for j:=1 to i-1 do
          sz[n].g[i-j]:=ord(s[j])-48;
        sz[n].g[0]:=i-1;
        delete(s,1,i);
        break;
      end;
    end;
    sz[n].p:=s;
  end;
  ans[0]:=32767;
  for i:=1 to n do
  begin
    fillchar(min,sizeof(min),0);
    for j:=1 to n do
    begin
      fillchar(t,sizeof(t),0);
      if i<>j then begin
        if dx(sz[j].g,sz[i].g) then
          jian(sz[j].g,sz[i].g)
        else
          jian(sz[i].g,sz[j].g);
        cheng(t,sz[j].num);
        jia(t);
      end;
    end;
    if dx(ans,min) then begin
      ans:=min;
      pla:=sz[i].p;
    end;
  end;
  write(pla);
  close(input);
  close(output);
end.