数据过水
查看原帖
数据过水
754938
ACdreamer楼主2025/1/23 11:15

这个代码AC了,但可以被:

4

1 1

2 1

3 1

4 1

1 1000

这组数据卡掉,答案是6,这个代码输出会输出很多奇怪的0,建议添加hack数据

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+50;
int n,it,a[N],c[N];
struct s{
	int l,r;	
}p[N];
bool cmp(s x,s y){
	return x.l*x.r<y.l*y.r;
}
void mul(int a[],int c){
	int t=0;
	for(int i=0;i<N;i++){
		t+=a[i]*c;
		a[i]=t%10;
		t/=10;
	}
}
void div(int a[],int b){
	int r;
	for(int i=N;i>=0;i--){
		r=r*10+a[i];
		c[i]=r/b;
		r=r%b;
	}
}
int main()
{
	cin>>n;
	if(n==1){
		cout<<0;
		return 0;
	}
	a[0]=1;
	for(int i=0;i<=n;i++){
		cin>>p[i].l>>p[i].r;
	}
	sort(p+1,p+1+n,cmp);
	for(int i=0;i<n;i++){
		int l=p[i].l;
		mul(a,l);
	}
	/*it=N-1;
	while(!a[it]&&it>=1)it--;
	for(int i=it;i>=0;i--){
		cout<<a[i];
	}
	cout<<endl;*/
	div(a,p[n].r);
	it=N-1;
	while(!c[it]&&it>=1)it--;
	if(c[it]==0){
		cout<<1;
		return 0;
	}
	for(int i=it;i>=0;i--){
		cout<<c[i];
	}
	
	return 0;
}
2025/1/23 11:15
加载中...