Problem Description
Each person had do something foolish along with his or her growth.But,when he or she did this that time,they could not predict that this thing is a mistake and they will want this thing would rather not happened.
The world king Sconbin is not the exception.One day,Sconbin was sleeping,then swakened by one nightmare.It turned out that his love letters to Dufein were made public in his dream.These foolish letters might ruin his throne.Sconbin decided to destroy the letters by the military exercises’s opportunity.The missile is the best weapon.Considered the execution of the missile,Sconbin chose to use one missile with the minimum destruction.
Sconbin had writen N letters to Dufein, she buried these letters on different places.Sconbin got the places by difficult,he wants to know where is the best place launch the missile,and the smallest radius of the burst area. Let’s help Sconbin to get the award.
Input
There are many test cases.Each case consists of a positive integer N(N<500,V,our great king might be a considerate lover) on a line followed by N lines giving the coordinates of N letters.Each coordinates have two numbers,x coordinate and y coordinate.N=0 is the end of the input file.
Output
For each case,there should be a single line in the output,containing three numbers,the first and second are x and y coordinates of the missile to launch,the third is the smallest radius the missile need to destroy all N letters.All output numbers are rounded to the second digit after the decimal point.
Sample Input
3
1.00 1.00 2.00
2.00 3.00 3.00
0
Sample Output
2.00 2.00 1.41
代码
#include<iostream>
#include<cmath>
using namespace std;
const int inf = 1e9+5;
const double eps = 1e-7;
const int maxn = 510;
int n;
struct Point
{
double x, y;
}P[maxn];
// 求两点距离
double getDist(Point a, Point b)
{
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
Point pos; // 初始圆心的位置
double ans; // 半径的结果
// 模拟退火算法
void min_circle(){
//初始温度
double T = 100;
//温度下降系数
double delta = 0.98;
while(T>eps)
{
// 距离圆心最远的点,默认将第1个点作为起始点
Point maxPoint = P[1];
// 不断的找到和该点距离最远的点为P[i]
for(int i = 2; i <= n; i++)
{
if(getDist(pos, P[i]) > getDist(pos, maxPoint))
maxPoint = P[i];
}
//这个时候再向maxPoint慢慢移动,重复下去,直到圆心这个点到所有点的最大距离不再变小的时候
//那么这个点就是最优圆的圆心了
ans = min(ans, getDist(pos, maxPoint));
pos.x += (maxPoint.x - pos.x) * T / 100.0;
pos.y += (maxPoint.y - pos.y) * T / 100.0;
T = T* delta;
}
}
int main()
{
while(cin>>n)
{
if(n == 0) break;
ans = inf;
pos.x=pos.y=0;
for(int i = 1; i <= n; i++)
cin>>P[i].x>>P[i].y;
min_circle();
printf("结果为:%.2f %.2f %.2f\n", pos.x, pos.y, ans);
}
return 0;
}
本文介绍了一个使用模拟退火算法寻找最小覆盖圆的问题。国王Sconbin希望销毁一些写给Dufein的信件,通过军事演习的机会发射导弹来实现这一目标。为了用最少的破坏力达到目的,我们需要确定导弹的最佳发射位置及其最小爆炸半径。文章提供了一段C++代码,用于解决这一问题,具体包括输入坐标、模拟退火过程及输出结果。
550

被折叠的 条评论
为什么被折叠?



