题目
题目大意
本题给出平面二维坐标上的若干个点,要求选取一个点做圆心,此时可以以最短半径包含所有点,求出圆心坐标和最短半径平方,结果保留两位小数。
解题思路
本题乍看只下可能觉得会很复杂,但结合数据组成和时间限制可以发现其实就是简单的暴力遍历问题。本题难点在于对于题目的理解细致程度,首先题目要求半径平方,不要只看样例忽略这一点。另外本题虽然要求保留两位小数,但实际上无论半径的平方还是点的坐标都是可以用整数来处理的,使用浮点数表示反倒会出现问题。最后要注意本题的半径平方不能简单的用int类型表示,从数据组成可以看出保险起见还是使用long long数据类型,那么这里就要注意初始最大值不能再设定为int类型下常用的1e9,而是要按照题目需求来设定,这里也是我在模测时出错的点。
具体代码
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include <map>
#define ll long long
#define MAXN 105
using namespace std;
struct point{
int x,y;
}p[1005];
bool cmp(struct point a,struct point b)
{
if(a.x != b.x)
{
return a.x < b.x;
}
return a.y < b.y;
}
int main()
{
int n;
scanf("%d",&n);
for(int i = 0; i < n; i++)
{
scanf("%d %d",&p[i].x,&p[i].y);
}
sort(p,p+n,cmp);
ll maxn = 1e11;
point tmp;
for(int i = 0; i < n; i++)
{
ll minn = -1;
for(int j = 0; j < n; j++)
{
ll plx = abs(p[i].x - p[j].x);
ll ply = abs(p[i].y - p[j].y);
ll l = plx * plx + ply * ply;
if(l > minn)
{
minn = l;
}
}
if(minn < maxn)
{
maxn = minn;
tmp.x = p[i].x;
tmp.y = p[i].y;
}
}
cout << tmp.x << ".00 " << tmp.y << ".00" << endl;
cout << maxn << ".00";
return 0;
}