练了一下高精度。。结果敲了这么久。。。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 1050 using namespace std; struct pnt { int x,y; }p[maxn]; int n,a,b; struct bign { int len,a[4050]; }; bign base,ans; bool cmp(pnt x,pnt y) { return max(y.y,x.y*x.x)<max(x.y,y.x*y.y); } void reset() { ans.len=0;ans.a[0]=0; int ret=a;base.len=0; while (ret) { base.a[base.len]=ret%10; ret/=10;base.len++; } base.len--; } bign operator / (bign x,int m) { int ret[4050],len=0,data=0; for (int i=x.len;i>=0;i--) { data=data*10+x.a[i]; ret[++len]=data/m;data%=m; } int now=1;while ((!ret[now]) && (now<=len)) now++; bign y; if (now==len+1) { y.len=0;y.a[0]=0; return y; } y.len=len-now; for (int i=y.len;i>=0;i--) { y.a[i]=ret[now]; now++; } return y; } bool operator > (bign x,bign y) { if (x.len<y.len) return false; if (x.len>y.len) return true; int top=x.len; for (int i=top;i>=0;i--) { if (x.a[i]>y.a[i]) return true; if (x.a[i]<y.a[i]) return false; } } bign operator * (bign x,int m) { bign y,ans; while (m) {y.a[y.len++]=m%10;m/=10;} y.len--; for (int i=0;i<=x.len+y.len+1;i++) ans.a[i]=0; for (int i=0;i<=x.len;i++) for (int j=0;j<=y.len;j++) ans.a[i+j]+=x.a[i]*y.a[j]; for (int i=0;i<=x.len+y.len;i++) { ans.a[i+1]+=ans.a[i]/10; ans.a[i]%=10; } ans.len=x.len+y.len; if (ans.a[x.len+y.len+1]) ans.len++; return ans; } int main() { scanf("%d",&n); scanf("%d%d",&a,&b); for (int i=1;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].y); sort(p+1,p+n+1,cmp); reset(); for (int i=1;i<=n;i++) { bign ret=base/p[i].y; if (ret>ans) ans=ret; base=base*p[i].x; } for (int i=ans.len;i>=0;i--) printf("%d",ans.a[i]); return 0; }
时间: 2024-10-23 04:34:19