比赛 五一大礼包 评测结果 AAAAAAAAAA
题目名称 国王游戏 最终得分 100
用户昵称 李金泽 运行时间 0.159 s
代码语言 C++ 内存使用 3.89 MiB
提交时间 2026-05-04 09:42:44
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define N 5005
#define int long long
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
int T,n,m,k,op,x,y,z;
struct node{int a,b;bool operator<(node y){return a*b<y.a*y.b;}}a[N];
struct big{
    int n,a[N];
    void operator=(int x){
        while(x)a[++n]=x%10,x/=10;
    }
    void operator=(big x){
        n=x.n;fo(i,1,n)a[i]=x.a[i];
    }
    void operator*=(int x){
        fo(i,1,n)a[i]*=x;
        fo(i,1,n){
            a[i+1]+=a[i]/10;
            a[i]%=10;
            if(a[n+1])n++;
        }
    }
    void chu(int x,big &ans){
        big c;c.n=0;
        for(int i=n,p=0;i;i--){
            p=p*10+a[i];
            if(p>=x){
                if(!c.n){
                    c.n=i;fo(i,1,n)c.a[i]=0;
                }
                c.a[i]=p/x;
                p%=x;
            }
        }
        if(c.n<ans.n)return;
        if(c.n>ans.n){ans=c;return;}
        rf(i,c.n,1)
            if(c.a[i]^ans.a[i]){
                if(c.a[i]<ans.a[i])return;
                ans=c;return;
            }
    }
    void output(){
        if(!n)printf("0");
        rf(i,n,1)printf("%lld",a[i]);
    }
}now,ans;
void swap(int &x,int &y){int t=x;x=y;y=t;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int fp(int a,int n,int mod){
    int ans=1;
    while(n){
        if(n&1)ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
int read(){
    int sum=0;bool f=0;char c=getchar();
    for(;c<48||c>57;c=getchar())if(c==45)f=1;
    for(;c>=48&&c<=57;c=getchar())sum=sum*10+(c&15);
    return f?-sum:sum;
}
signed main(){
    freopen("kinggame.in","r",stdin);freopen("kinggame.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    n=read();
    fo(i,0,n)a[i]={read(),read()};
    sort(a+1,a+n+1);
    now=a[0].a;
    fo(i,1,n){
        now.chu(a[i].b,ans);
        now*=a[i].a;
    }
    ans.output();
}