请教一下代码
查看原帖
请教一下代码
1123386
bzqd楼主2024/1/13 16:07
 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll base=10;
struct node
{
	ll len,s[4300];
	node() {len=1;memset(s,0,sizeof(0));}
	node(ll x)
	{
		len=1;
		memset(s,0,sizeof(s));
		ll i=0;
		while(x)
		{
			s[++i]=x%10;
			x/=10;
		}
		len=i;
	}
};
struct d
{
	ll l,r;
}f[1010];
node operator * (const node &a,const ll b)
{
	node c;
	c.len=a.len;
	for(ll i=1;i<=a.len;i++)
	{
		c.s[i]+=a.s[i]*b;
		c.s[i+1]+=c.s[i]/base;
		c.s[i]%=base;
	}
	if(c.s[c.len+1])
	{
		ll x=c.s[c.len+1],len=c.len;
		while(x)
		{
			c.s[++len]=x%base;
			x/=base;
		}
		c.len=len;
	}
	return c;
}
node operator / (const node &a,const ll &b)
{
	node c;
	c.len=a.len;
	ll x=0;
	for(ll i=a.len;i>=1;i--)
	{
		x=x*base+a.s[i];
		c.s[i]=x/b;
		x%=b;
	}
	while(!c.s[c.len]&&c.len>1) c.len--;
	return c;
}
bool operator < (const node &a,const node &b)
{
	if(a.len==b.len)
	{
		for(ll i=a.len;a.s[i]==b.s[i]&&i>1;i--)
		{
			if(i>=1) return a.s[i]<b.s[i];
			else return false;
		}
	}
	else return a.len<b.len;
}
void print(const node &a)
{
	for(ll i=a.len;i>=1;i--)
	{
		printf("%lld",a.s[i]);
	}
}
bool cmp(const d x,const d y)
{
	return x.l*x.r<y.l*y.r;
}
node ans;
int main()
{
	ll n;
	scanf("%lld",&n);
	for(ll i=0;i<=n;i++)
	{
		scanf("%lld%lld",&f[i].l,&f[i].r);
	}
	sort(f+1,f+n+1,cmp);
	node k(1);
	for(ll i=1;i<=n;i++)
	{
		if(f[i-1].l==0) break;
		k=k*f[i-1].l;
		node t;
		t=k/f[i].r;
		if(ans<t) ans=t;
	}
	print(ans);
	return 0;
}

有没有大佬帮我看看出了什么问题?就过了最后一个点

2024/1/13 16:07
加载中...