求助这段代码,悬一关
  • 板块学术版
  • 楼主GinoZQwQ
  • 当前回复2
  • 已保存回复2
  • 发布时间2025/8/4 10:42
  • 上次更新2025/8/4 16:24:41
查看原帖
求助这段代码,悬一关
909552
GinoZQwQ楼主2025/8/4 10:42

下面这段是某道站外题的代码,结果当n=4000的时候,程序会卡在cout<<cl<<" "<<cr<<"::\n";前面。(正常不应该输入都超时啊qwq)

求大佬调试qaq

#include<iostream>
#include<fstream>
#include<algorithm>
#define INFINT 2147483647
#define feq(a,b) (abs(a-b)<=1e-6)
//#define upp(x) (upper_bound(h+1,h+ch+1,x))
//#define lww(x) (lower_bound(h+1,h+ch+1,x))
typedef long long LL_INT;

using namespace std;
int n,pi,ai,bi,cl=0,cr=0,ch=0;
double h[4010];
double l[4010],r[4010];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>pi>>ai>>bi;
		double hr=((double)ai/(ai+bi));
		if(pi==0)      h[++ch]=hr;
		else if(pi==1) l[++cl]=hr;
		else           r[++cr]=hr;
	}
	l[++cl]=1;
	r[++cr]=1;
	h[++ch]=1;
	cout<<cl<<" "<<cr<<"::\n";
	sort(h+1,h+ch+1);
//	long long ans=0;auto wn=h+ch+1;
//	if(n==0){
//		cout<<1;return 0;
//	}
//	for(int ii=1;ii<=cl;ii++){
//		for(int jj=1;jj<=cr;jj++){
//			double i=l[ii],j=r[jj];
//			double hi=2.0-(i+j);
//			if(hi>1.0)continue;
//			auto uk=upper_bound(h+1,h+ch+1,hi);auto sw=uk;uk--;
//			auto uw=lower_bound(h+1,h+ch+1,max(1.0-i,1.0-j));
//			if(uk==h)uk=h+1;
//			//cout<<*(h.lower_bound(hi))<<" "<<*(uk)<<'\n';
//			if(feq(*sw,hi)||feq(*uk,hi))ans+=(wn-uw)-1;
//			else ans+=(wn-uw);
//		}
//	}
//	cout<<ans;
	return 0;
}
2025/8/4 10:42
加载中...