1 条题解
-
0
C++ :
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,a,b; struct _{int a,b;}__[10003]; bool pp(_ a,_ b){return a.b*a.a<b.b*b.a;}; struct big{ int n; int a[16003]; void operator*=(int b){ for(int i=0;i<n;++i) a[i]*=b; for(int i=0;i<n;++i) if(a[i]>9){ a[i+1]+=a[i]/10; a[i]%=10; } while(a[n]>9){ a[n+1]=a[n]/10; a[n]%=10; ++n; } if(a[n])++n; } bool operator>(big b){ if(n!=b.n) return n>b.n?1:0; for(int i=n-1;i>=0;++i) if(a[i]!=b.a[i]) return a[i]>b.a[i]?1:0; return 0; } big operator/(int b){ bool flag=0; big res; memset(res.a,0,sizeof res.a); res.n=0; int now=0; for(int i=n-1;i>=0;--i){ now=now*10+a[i]; if(now>=b){ if(!flag) res.n=i+1,flag=1; res.a[i]=now/b; now%=b; } } return res; } }now,ans; int main(){ scanf("%d%d%d",&n,&a,&b); for(int i=0;i<n;++i) scanf("%d%d",&__[i].a,&__[i].b); sort(__,__+n,pp); while(a){ now.a[now.n++]=a%10; a/=10; } for(int i=0;i<n;++i){ big stay=now/__[i].b; ans=ans>stay?ans:stay; now*=__[i].a; } for(int i=ans.n-1;i>=0;--i) printf("%d",ans.a[i]); return 0; }
Pascal :
var n,i,j,t:longint;d,ans,max,e:ansistring; a,b,c:array[1..1010]of longint; function gcd2(a:ansistring;b:longint):ansistring; var i,j,lena,lenc,c:longint; x,y:array[1..4010]of longint; begin fillchar(x,sizeof(x),0); fillchar(y,sizeof(y),0); lena:=length(a); for i:=1 to lena do x[i]:=ord(a[i])-48; c:=0; for i:=1 to lena do begin y[i]:=(c*10+x[i]) div b; c:=(c*10+x[i]) mod b; end; lenc:=1; while (y[lenc]=0)and(lenc<lena) do inc(lenc); gcd2:=''; for i:=lenc to lena do gcd2:=gcd2+chr(y[i]+48); end; function gcd1(a,b:ansistring):ansistring; var i,j,lena,lenb,lenc:longint; x,y,z:array[1..4010]of longint; begin fillchar(x,sizeof(x),0); fillchar(y,sizeof(y),0); fillchar(z,sizeof(z),0); lena:=length(a); lenb:=length(b); for i:=1 to lena do x[i]:=ord(a[lena+1-i])-48; for i:=1 to lenb do y[i]:=ord(b[lenb+1-i])-48; for i:=1 to lena do for j:=1 to lenb do begin z[i+j-1]:=z[i+j-1]+x[i]*y[j]; z[i+j]:=z[i+j]+z[i+j-1] div 10; z[i+j-1]:=z[i+j-1] mod 10; end; lenc:=lena+lenb; while (lenc>1)and(z[lenc]=0) do dec(lenc); gcd1:=''; for i:=lenc downto 1 do gcd1:=gcd1+chr(z[i]+48); end; begin read(n); for i:=1 to n+1 do begin read(a[i],b[i]); c[i]:=a[i]*b[i]; end; for i:=2 to n do for j:=i+1 to n+1 do if c[i]>c[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; end; str(a[1],ans); max:='0';e:='0'; for i:=2 to n+1 do begin str(a[i],d); e:=gcd2(ans,b[i]); ans:=gcd1(ans,d); if (length(e)>length(max))or((length(e)=length(max))and(e>max)) then max:=e; end; writeln(max); end.
- 1
信息
- ID
- 306
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者