为什么 long double 过不了样例 4?
查看原帖
为什么 long double 过不了样例 4?
466276
huangjinxiu楼主2025/1/18 18:42

rt,将代码第9行的 double 改成long double
输出 :815899161079.399999976158 样例4:815899161079.400024414062

#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define pb emplace_back
#define cmin(a,b) ((a)=min((a),(b)))
#define cmax(a,b) ((a)=max((a),(b)))
#define int long long
#define ld double 
using namespace std;
namespace IO{
	const int maxn=(1<<20);char *p1,*p2,buf[maxn];
	#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,maxn,stdin),p1==p2)?EOF:*p1++)
	int read(){
		int f=1,k=0;char c;
		while(!isdigit(c=gc()))if(c=='-')f=-1;
		while(isdigit(c))k=k*10+c-48,c=gc();
		return f*k;
	}
}using namespace IO;
const int N=2e5+10; 
ld ans;int a[N],b[N],d[N],c[N],tmp[N],st[N],top,n,vpos,pos;
inline int nxt(int x){return x%n+1;}
void rebuild(int *a){
	int cur=pos;
	for(int i=1;i<=n;++i)tmp[i]=a[cur=nxt(cur)];
	tmp[0]=a[pos];
	for(int i=0;i<=n;++i)a[i]=tmp[i];
}
struct Line{
	ld k,b;
	void init(ld x1,ld y1,ld x2,ld y2){
		k=(y1-y2)/(x1-x2);
		b=y1-x1*k;
	}
	ld get(ld x){
		return x*k+b;
	}
}line;
signed main(){
	n=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
		if(a[i]>vpos){
			vpos=a[i];
			pos=i;
		}
	}
	for(int i=1;i<=n;++i)b[i]=read();
	rebuild(a);rebuild(b); 
	for(int i=2;i<=n;++i)d[i]=2*(d[i-1]-b[i-1])-d[i-2]; 
	for(int i=0;i<=n;++i)c[i]=a[i]+d[i];
	for(int i=0;i<=n;++i){
		while(top>1&&((c[st[top]]-c[st[top-1]])*(i-st[top])<=(c[i]-c[st[top]])*(st[top]-st[top-1])))--top;
		st[++top]=i;
	}
	for(int i=1;i<top;++i){
		line.init(st[i],c[st[i]],st[i+1],c[st[i+1]]);
		for(int j=st[i];j<st[i+1];++j)ans+=line.get(j)-d[j];
	}
	cout<<fixed<<setprecision(12)<<ans/n<<'\n';
	return 0;
}
2025/1/18 18:42
加载中...