社区讨论

三分 90 pts 求调

P1158[NOIP 2010 普及组] 导弹拦截参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@lo1up318
此快照首次捕获于
2023/10/23 03:17
2 年前
此快照最后确认于
2023/11/03 03:48
2 年前
查看原帖
RT
CPP
// author: syl
// language: c++
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5+5;
pair<int,int> d[N];
int xa,ya,xb,yb;
int getdis(int a,int b,int x,int y) {
	return (a-x)*(a-x)+(b-y)*(b-y);
}
int f(int a,int n) {
	int res=0;
	for(int i=1;i<=n;++i) {
		if(getdis(xa,ya,d[i].first,d[i].second)<=a) continue;
		res=max(res,getdis(xb,yb,d[i].first,d[i].second));
	} return res+a;
}
int bbsearch(int l,int r,int n) {
	while(l<r-1) {
		int m1=l+r>>1,m2=m1+r>>1;
		if(f(m1,n)<f(m2,n)) r=m2;
		else l=m1;
	} return min(f(l,n),f(r,n));
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr),
	cout.tie(nullptr);
	cin>>xa>>ya>>xb>>yb;
	int n;
	cin>>n;
	for(int i=1;i<=n;++i) cin>>d[i].first>>d[i].second;
	cout<<bbsearch(0,1e15,n);
	return 0;
}

回复

1 条回复,欢迎继续交流。

正在加载回复...