#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> #include<cmath> using namespace std; int read() { int x=0,f=1;char ch=getchar(); while(ch<‘0‘ || ch>‘9‘) { if(ch==‘-‘) f=-1; ch=getchar(); } while(ch>=‘0‘ && ch<=‘9‘) { x=x*10+ch-‘0‘; ch=getchar(); } return x*f; } struct node { int a,b; }f[1005]; bool cmp(node x,node y) { return x.a*x.b<y.a*y.b; } int n,kinga,kingb,ans[100005],add[100005],sum[100005]; int i,k; void cheng(int x) { memset(add,0,sizeof(add)); int j; for(j=1;j<=ans[0];j++) { ans[j]*=x; add[j+1]+=ans[j]/10; ans[j]%=10; } for(j=1;j<=ans[0]+4;j++)//max 1000 { ans[j]+=add[j]; ans[j+1]+=ans[j]/10; ans[j]%=10; if(ans[j]!=0) ans[0]=max(ans[0],j); } return ; } void chu(int x) { int j; memset(add,0,sizeof(add)); int q=0; for(j=ans[0];j>=1;j--) { q*=10; q+=ans[j]; add[j]=q/x; if(add[0]==0 && add[j]!=0) { add[0]=j; } q%=x; } return ; } bool my_max() { if(sum[0]>add[0]) return 0; if(sum[0]<add[0]) return 1; int j; for(j=add[0];j>=1;j--) { if(add[j]<sum[j]) return 0; if(add[j]>sum[j]) return 1; } return 0; } void my_ans() { int j; memset(sum,0,sizeof(sum)); for(j=add[0];j>=0;j--) sum[j]=add[j]; return ; } int main() { n=read(); f[0].a=read(); f[0].b=read(); for(i=1;i<=n;i++) { f[i].a=read(); f[i].b=read(); } sort(f+1,f+n+1,cmp); ans[0]=ans[1]=1; for(i=1;i<=n;i++) { //cout<<"*"<<ans[0]<<"*"; cheng(f[i-1].a); chu(f[i].b); if(my_max()) { my_ans(); } //for(k=1;k<=ans[0];k++) cout<<add[k]; //cout<<endl; } for(i=sum[0];i>=1;i--) printf("%d",sum[i]); return 0; }
原文:https://www.cnblogs.com/llllllpppppp/p/9124400.html