T2 - ZJM要抵御宇宙射线
题目描述
题目思路
这个题目其实上降低了一点难度,因为它规定保护罩的中心是位于一个宇宙射线的发射点上的。这样我们就只需要遍历所有的点,然后找到每个点以它为圆心包含所有点的最小圆,即找出距离中心点最远的点。然后再在所有的圆里面找到面积最小的圆即可。如果没有规定保护罩的中心在宇宙射线的发射点上的话就会稍微麻烦一点。
代码实现
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 1010;
const double inf = 1e12;
int n;
struct circle{
double x,y;
double area;
circle(){
x = y = 0;
area = inf;
}
bool operator < (const circle& t)const{
if(area != t.area) return area < t.area;
else if(x != t.x) return x < t.x;
else return y < t.y;
}
}c[N],ans;
double getarea(circle& s,circle& t){
return ((s.x - t.x) * (s.x - t.x) + (s.y - t.y) * (s.y - t.y));
}
int main(){
scanf("%d",&n);
for(int i = 0; i < n; i++){
scanf("%lf%lf",&c[i].x,&c[i].y);
}
for(int i = 0; i < n; i++){
double maxarea = 0;
for(int j = 0; j < n; j++){
maxarea = max(maxarea,getarea(c[i],c[j]));
}
c[i].area = maxarea;
if(c[i] < ans){
ans = c[i];
}
}
printf("%.2lf %.2lf\n%.2lf",ans.x,ans.y,ans.area);
}