救救孩子吧
查看原帖
救救孩子吧
286571
Crane_NF楼主2023/3/4 10:46

洛谷全对,一本通一个都不过,全是答案错误.....

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
struct nd
{
	int left;
	int right;
}dc[N];
int kl,kr;
int n,l1;
string lj,ma,te;
bool cmp(nd x,nd y)
{
	if(x.left*x.right==y.left*y.right)
		return x.left<y.left;
	return x.left*x.right<y.left*y.right;
}
string fz(string x)
{
	string t;
	for(int i=x.size()-1;i>=0;i--)
		t+=x[i];
	return t;
}
string cf(string a,int b1)
{
	a=fz(a);
	string c,ans;
	int r=0;
	int na=a.size();
	for(int i=0;i<na;i++)
	{
		r=r*10+(a[i]-'0');
		c+=r/b1+'0';
		r%=b1;
	}
	int pos=0;
	while(c[pos]=='0'&&pos<=na)
		pos++;
	if(pos>=na)
		return "1";
	for(int i=pos;i<=na;i++)
		ans+=c[i];
	return fz(ans);
} 
string maxx(string x,string y)
{
	x=fz(x);
	if(x.size()>y.size())
		return x;
	if(x>y)
		return x;
	return y;
}
string xc(string a,int b1)
{
	a=fz(a);
	string c;
	if(b1==0)
		return "0";
	int sum=0;
	for(int na=a.size()-1;na>=0;na--)
	{
		int k=a[na]-'0';
		sum+=k*b1;
		c+=sum%10+'0';
		sum/=10;
	}
	if(sum>0)
		while(sum)
			c+=sum%10+'0',sum/=10;
	return c;
} 
int main()
{
	int t;
	cin>>n>>kl>>kr;
	t=kl;
	while(t)
	{
		lj+=t%10+'0';
		t/=10;
	}
	for(int i=1;i<=n;i++)
		scanf("%d %d",&dc[i].left,&dc[i].right);
	sort(dc+1,dc+n+1,cmp);
	ma+='0';
	int num=0;
	for(int i=1;i<=n;i++)
	{
		te=cf(lj,dc[i].right);//反 
		ma=maxx(te,ma);//正 
		lj=xc(lj,dc[i].left);//反 
		if(dc[i].left==2)
			num++;
	}
	cout<<ma;
	return 0;
}
/*
5 3
6 2
8 4
9 1


9 1
6 2
5 3
8 4
*/
2023/3/4 10:46
加载中...