国王游戏
贪心策略较为简单,可以邻项考虑,式子化简后按照x*y排序即可
要用到高精度乘除。。
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define U(i,u) for(register ll i=head[u];i;i=nxt[i])
#define rep(i,a,b) for(register ll i=(a);i<=(b);++i)
#define per(i,a,b) for(register ll i=(a);i>=(b);--i)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> PII;
typedef vector<int> VI;
template<class T> inline void read(T &x){
x=0;char c=getchar();int f=1;
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}x*=f;
}
template<class T> inline void cmin(T &x, T y){x=x<y?x:y;}
template<class T> inline void cmax(T &x, T y){x=x>y?x:y;}
const int N=200001;
int n;
int tim[N],ans[N],mx[N],tmp[N];
struct node{
int x,y;
}d[N];
bool cmp(node a,node b){
return a.x*a.y<b.x*b.y;
}
void mul(int a[],int b){
int len1=a[0],len2=len1;
memset(tmp,0,sizeof(tmp));
rep(i,1,len1){
tmp[i]+=a[i]*b;
tmp[i+1]+=tmp[i]/10;
tmp[i]%=10;
}
while(tmp[len2+1]>0){
++len2;
tmp[len2+1]+=tmp[len2]/10;
tmp[len2]%=10;
}
tim[0]=len2;rep(i,1,len2){tim[i]=tmp[i];}
}
void div(int a[],int b,int c[]){
memset(ans,0,sizeof(ans));
int len=a[0],d=0;per(i,len,1){
c[i]=(d*10+a[i])/b;
d=(d*10+a[i])%b;
if(c[0]==0&&c[i]!=0)c[0]=i;
}
ans[0]=c[0];rep(i,1,c[0])ans[i]=c[i];
}
bool compare(int a[],int b[]){
if(a[0]==b[0]){
per(i,a[0],1){
if(a[i]>b[i])return 1;
if(a[i]<b[i])return 0;
}
}
if(a[0]>b[0])return 1;
else if(a[0]<b[0])return 0;
else return 0;
}
void cp(){
memset(mx,0,sizeof(mx));
mx[0]=ans[0];rep(i,1,mx[0]){
mx[i]=ans[i];
}
}
int main(){
read(n);rep(i,1,n+1){
read(d[i].x);read(d[i].y);
}
sort(d+2,d+n+2,cmp);
tim[0]=1;tim[1]=1;
mul(tim,d[1].x);
rep(i,2,n+1){
div(tim,d[i].y,ans);
if(compare(ans,mx)){
cp();
}
mul(tim,d[i].x);
}
per(i,mx[0],1){
printf("%d",mx[i]);
}
return 0;
}