hdu 3007(模拟退火算法)

本文介绍了一个使用模拟退火算法寻找最小覆盖圆的问题。国王Sconbin希望销毁一些写给Dufein的信件,通过军事演习的机会发射导弹来实现这一目标。为了用最少的破坏力达到目的,我们需要确定导弹的最佳发射位置及其最小爆炸半径。文章提供了一段C++代码,用于解决这一问题,具体包括输入坐标、模拟退火过程及输出结果。
Wan2.2-T2V-A5B

Wan2.2-T2V-A5B

文生视频
Wan2.2

Wan2.2是由通义万相开源高效文本到视频生成模型,是有​50亿参数的轻量级视频生成模型,专为快速内容创作优化。支持480P视频生成,具备优秀的时序连贯性和运动推理能力

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;
}

您可能感兴趣的与本文相关的镜像

Wan2.2-T2V-A5B

Wan2.2-T2V-A5B

文生视频
Wan2.2

Wan2.2是由通义万相开源高效文本到视频生成模型,是有​50亿参数的轻量级视频生成模型,专为快速内容创作优化。支持480P视频生成,具备优秀的时序连贯性和运动推理能力

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值