跳到正文

个人记录

CF780B

yanziwei88约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年7月19日
更新
2026年7月19日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
const int N=1e5+9;
const ld eps=1e-6;
int n,A,B;
ld a[N],b[N];
bool check(ld x){
	ld mx=-1e18,mn=1e9;
	for(int i=1;i<=n;i++){
		mn=min(mn,a[i]+1.0*x*b[i]);
		mx=max(mx,a[i]-1.0*x*b[i]);
	}
	return mn>=mx;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);  
    cout.tie(0); 
    cin>>n;
    for(int i=1;i<=n;i++){
		cin>>a[i];
		
	}
    for(int i=1;i<=n;i++){
		cin>>b[i];
		
	}
	ld l=0,r=1e9,ans=0;
	while(r-l>eps){
		ld mid=(l+r)/2;
		if(check(mid)){
			ans=mid;
			r=mid;
		}else{
			l=mid;
		}
	}
	cout<<fixed<<setprecision(10)<<ans;
    return 0;
}
原文