20分玄关
查看原帖
20分玄关
947986
luduoduo2023楼主2025/1/18 20:58
#include<bits/stdc++.h>
using namespace std;
int n,a[1005],b[1005],c[1005];
struct node {
	int l,r,t;
}sum[1005];
bool pos(node l,node r) {
	return l.t<r.t;
}
string deal(int x){
	string s="";
	while(x!=0) {
		char ch=(x%10)+'0';
		x/=10;
		s=ch+s;
	}
	return s;
}
string mul(string s1,int q) {
	string s2=deal(q);
	reverse(s1.begin(),s1.end());
	reverse(s2.begin(),s2.end());
	for(int i=0;i<=s1.size()-1;i++) a[i]=s1[i]-'0';
	for(int i=0;i<=s2.size()-1;i++) b[i]=s2[i]-'0';
	memset(c,0,sizeof(c));
	int lena=s1.size()-1,lenb=s2.size()-1;
	for(int i=0;i<=lena;i++) {
		for(int j=0;j<=lenb;j++) {
			c[i+j]+=a[i]*b[i];
			c[i+j+1]+=c[i+j]/10;
			c[i+j]%=10;
		}
	}
	int lenc=lena+lenb+1;
	while(c[lenc]==0&&lenc>0) lenc--;
	string ans="";
	for(int i=lenc;i>=0;i--) {
		char ch=c[i]+'0';
		ans+=ch;
	}
	return ans;
}
string div(string s1,int q) {
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	int len=s1.size()-1;
	for(int i=0;i<=len;i++) a[i]=s1[i]-'0';
	long long x=0;
	for(int i=0;i<=len;i++) {
		b[i]=(x*10+a[i])/q;
		x=(x*10+a[i])%q;
	}
	int l=0;
	while(b[l]==0&&l<len) l++;
	string s="";
	for(int i=1;i<=len;i++){
		char ch=b[i]+'0';
		s=s+ch;
	}
	return s;
}
int main() {
	cin>>n;
	for(int i=1;i<=n+1;i++) {
		cin>>sum[i].l>>sum[i].r;
		sum[i].t=sum[i].l*sum[i].r;
	}
	sort(sum+2,sum+(n+1)+1,pos);
	string t="1",ans="1";
	t=mul(t,sum[1].l);
	for(int i=2;i<=n+1;i++) {
		string x=div(t,sum[i].r);
		if(x.size()>ans.size()) ans=x;
		else if(x.size()==ans.size()&&x>ans) ans=x;
		t=mul(t,sum[i].l);
	}
	cout<<ans;
	return 0;
}
2025/1/18 20:58
加载中...