vijos 1779 国王游戏

时间:2023-01-31 05:41:00

练了一下高精度。。结果敲了这么久。。。

#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[];
};
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=;ans.a[]=;
int ret=a;base.len=;
while (ret)
{
base.a[base.len]=ret%;
ret/=;base.len++;
}
base.len--;
}
bign operator / (bign x,int m)
{
int ret[],len=,data=;
for (int i=x.len;i>=;i--)
{
data=data*+x.a[i];
ret[++len]=data/m;data%=m;
}
int now=;while ((!ret[now]) && (now<=len)) now++;
bign y;
if (now==len+)
{
y.len=;y.a[]=;
return y;
}
y.len=len-now;
for (int i=y.len;i>=;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>=;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%;m/=;}
y.len--;
for (int i=;i<=x.len+y.len+;i++) ans.a[i]=;
for (int i=;i<=x.len;i++)
for (int j=;j<=y.len;j++)
ans.a[i+j]+=x.a[i]*y.a[j];
for (int i=;i<=x.len+y.len;i++)
{
ans.a[i+]+=ans.a[i]/;
ans.a[i]%=;
}
ans.len=x.len+y.len;
if (ans.a[x.len+y.len+]) ans.len++;
return ans;
}
int main()
{
scanf("%d",&n);
scanf("%d%d",&a,&b);
for (int i=;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].y);
sort(p+,p+n+,cmp);
reset();
for (int i=;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>=;i--) printf("%d",ans.a[i]);
return ;
}