记录编号 343943 评测结果 AAAAAAAAAA
题目名称 [NOIP 2012]国王游戏 最终得分 100
用户昵称 GravatarNBWang 是否通过 通过
代码语言 Pascal 运行时间 0.653 s
提交时间 2016-11-09 20:01:19 内存使用 1.00 MiB
显示代码纯文本
program wz;
var
a,b,c:array[0..11000]of int64;
g:array[0..110000]of int64;

n,l:int64;
i:longint;

 procedure cheng;
 var
 j:longint;
 begin
 for j:=1 to l do g[j]:=g[j]*b[i];
 for j:=1 to l do
 begin
 g[j+1]:=g[j+1]+g[j] div 10;
 g[j]:=g[j] mod 10;
 end;
 inc(l);
 while g[l]>9 do
 begin
 g[l+1]:=g[l+1]+g[l]div 10;
 g[l]:=g[l] mod 10;
 inc(l);
 end;
 if g[l]=0 then dec(l);

 end;

 procedure chu;
 var
 j:longint;
 begin
 for j:=l downto 1 do
 begin
 g[j-1]:=g[j-1]+(g[j] mod c[n])*10;
 g[j]:=g[j] div c[n];
 end;
 while g[l]=0 do dec(l);

 end;

 procedure sort(x,y:int64);
 var
 i,j,mid,t:int64;
 begin
 i:=x;
 j:=y;
 mid:=a[(i+j) div 2];
 repeat
 while a[i]<mid do inc(i);
 while a[j]>mid 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;
 t:=c[i];c[i]:=c[j];c[j]:=t;
 inc(i);dec(j);
 end;
 until i>j;
 if i<y then sort(i,y);
 if j>x then sort(x,j);
 end;


begin
assign(input,'kinggame.in');
assign(output,'kinggame.out');
reset(input);
rewrite(output);

readln(n);
readln(b[0],c[0]);
for i:=1 to n do
begin
readln(b[i],c[i]);
a[i]:=b[i]*c[i];
end;
if (b[1]=1)and(b[2]=1) then begin writeln(1);halt;end;

sort(1,n);
l:=1;
g[1]:=b[0];
for i:=1 to n-1 do cheng;
chu;
for i:=l downto 1 do write(g[i]);

close(input);
close(output);
end.