noip2012国王游戏

来源:互联网 发布:dnf客户端深度优化 编辑:程序博客网 时间:2024/04/29 06:45
program tt;var ans,c,d:array[1..5000]of integer;    a,b:array[0..1000]of longint;    t,p,x,i,j,n,lc,ld,lans:longint;procedure qsort(x,y:longint);var i,j,mid,t:longint;begin i:=x;j:=y; mid:=a[(x+y) div 2]*b[(x+y) div 2]; repeat  while a[i]*b[i]<mid do i:=i+1;  while a[j]*b[j]>mid do j:=j-1;  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;    i:=i+1;j:=j-1;   end; until i>j; if i<y then qsort(i,y); if x<j then qsort(x,j);end;procedure chu(dd:longint);var len,k,i:longint;begin len:=lc;k:=0; for i:=len downto 1 do  begin   k:=k*10000+c[i];   d[i]:=k div dd;   k:=k mod dd;  end; while (d[len]=0)and(len>1) do len:=len-1; ld:=len;end;function compare:boolean;//!!,改为万位同样适用var i:longint;begin for i:=ld downto 1 do  begin   if d[i]>ans[i] then exit(true);   if d[i]<ans[i] then exit(false);  end; exit(false);end;procedure print;//!!万位的输出补0var i:longint;begin write(ans[lans]); for i:=lans-1 downto 1 do  begin   if ans[i]<10 then write(0);   if ans[i]<100 then write(0);   if ans[i]<1000 then write(0);   write(ans[i]);  end;end;begin read(n); read(a[0],b[0]); for i:=1 to n do read(a[i],b[i]); qsort(1,n); while a[0]>0 do  begin   lc:=lc+1;   c[lc]:=a[0] mod 10000;   a[0]:=a[0] div 10000;  end; for i:=1 to n do  begin   chu(b[i]);   if lans<ld then begin    lans:=ld;    ans:=d;   end   else    if lans=ld then     if compare then ans:=d;   x:=0;   for j:=1 to lc do    begin     x:=x+c[j]*a[i];     c[j]:=x mod 10000;     x:=x div 10000;    end;   while x>0 do    begin     lc:=lc+1;     c[lc]:=x mod 10000;     x:=x div 10000;    end;  end; print; readln;readln;end.

0 0
原创粉丝点击