HDU 3007 模拟退火算法

Buried memory

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4067    Accepted Submission(s): 2171

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

做法类似POJ2069

请参考:https://www.cnblogs.com/qq965921539/p/9806603.html

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <map>
 6 #include <set>
 7 #include <list>
 8 #include <deque>
 9 #include <queue>
10 #include <stack>
11 #include <vector>
12 #include <cmath>
13 #include <algorithm>
14 using namespace std;
15 #define it iterator
16 #define ll long long
17 #define eb emplace_back
18 #define lowbit(x) x & -x
19 #define all(x) x.begin(),x.end()
20 #define ZERO(a) memset(a,0,sizeof(a))
21 #define MINUS(a) memset(a,0xff,sizeof(a))
22 #define per(x,a,b) for(int x = a; x <= b; x++)
23 #define rep(x,a,b) for(int x = a; x >= b; x--)
24 #define IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
25
26 const int birth = 19260817;
27 const int mo = 998244353;
28 const int maxn = 1e5 + 10;
29 const int mod = 1e9 + 7;
30 const int INF = 0x3fffffff;
31 const double eps = 1e-8;
32
33 //******************THE PROGRAM BEGINING******************
34 struct node
35 {
36     double x, y;
37 }p[510],now;
38
39 double dis(node a, node b)
40 {
41     return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
42 }
43
44 double solve(int n)
45 {
46     double ans, cmp;
47     double T = 100.0;
48     double delat = 0.98;
49     now.x = now.y = 0.0;
50     int pos = 0;
51     while (T > eps)
52     {
53         pos = 0;
54         ans = dis(now, p[pos]);
55         per(i, 0, n - 1)
56         {
57             cmp = dis(now, p[i]);
58             if (cmp > ans)
59             {
60                 pos = i;
61                 ans = cmp;
62             }
63         }
64         now.x += (p[pos].x - now.x) / ans * T;
65         now.y += (p[pos].y - now.y) / ans * T;
66         T *= delat;
67     }
68     return ans;
69 }
70
71 int main()
72 {
73     int n;
74     while (scanf("%d", &n) && n)
75     {
76         per(i, 0, n - 1)
77             scanf("%lf %lf", &p[i].x, &p[i].y);
78         double ans = solve(n);
79         printf("%.2lf %.2lf %.2lf\n", now.x, now.y, ans);
80     }
81     return 0;
82 }

原文地址:https://www.cnblogs.com/qq965921539/p/9806780.html

时间: 2024-10-08 04:11:50

HDU 3007 模拟退火算法的相关文章

HDU - 3932 Groundhog Build Home 模拟退火算法

Groundhogs are good at digging holes, their home is a hole, usually a group of groundhogs will find a more suitable area for their activities and build their home at this area .xiaomi has grown up, can no longer live with its parents.so it needs to b

poj-2420 A Star not a Tree?(模拟退火算法)

题目链接: A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5219   Accepted: 2491 Description Luke wants to upgrade his home computer network from 10mbs to 100mbs. His existing network uses 10base2 (coaxial) cables that allo

PKU 1379 Run Away(模拟退火算法)

题目大意:原题链接 给出指定的区域,以及平面内的点集,求出一个该区域内一个点的坐标到点集中所有点的最小距离最大. 解题思路:一开始想到用随机化算法解决,但是不知道如何实现.最后看了题解才知道原来是要用模拟退火算法解决. 不过个人感觉这个算法的实现过程中仍然采用了随机化算法.二者均属于概率算法.  参考链接 Point Goto_Rand_Dir(double key,Point temp)函数中,Point temp必须得定义在参数中,不能定义在函数内部, 否则temp没有初始值,无法进行后面的

两种改进的模拟退火算法求解大值域约束满足问题1.0

0引言 约束满足问题(Constraint Satisfaction Problem,CSP)是人工智能研究领域中一个非常重要的分支,现已成为理论计算机科学.数学和统计物理学等交叉学科研究中的热点问题.人工智能.计算机科学和自动控制等领域中的许多问题都可以归结为约束满足问题.同时,约束满足问题在实际问题如模式识别.决策支持.物流调度及资源分配等领域也有着非常广泛的应用. CSP由一个变量集合和一个约束集合组成.每个变量都有一个非空的可能值域,每个约束描述了一个变量子集与子集内各变量的相容赋值,所

Matlab随笔之模拟退火算法

问题描述: 我方有一个基地,经度和纬度为( 70,40).假设我方飞机的速度为 1000 公里/小时. 我方派一架飞机从基地出发,侦察完敌方所有目标,再返回原来的基地.在敌方每一目 标点的侦察时间不计,求该架飞机所花费的时间(假设我方飞机巡航时间可以充分长). 这是一个旅行商问题.我们依次给基地编号为 1,敌方目标依次编号为 2, 3,…, 101, 最后我方基地再重复编号为 102(这样便于程序中计算). 距离矩阵 D = ( dij )102×102 , 其中 dij 表示表示 i, j 两

大白话解析模拟退火算法(转)

优化算法入门系列文章目录(更新中): 1. 模拟退火算法 2. 遗传算法 一. 爬山算法 ( Hill Climbing ) 介绍模拟退火前,先介绍爬山算法.爬山算法是一种简单的贪心搜索算法,该算法每次从当前解的临近解空间中选择一个最优解作为当前解,直到达到一个局部最优解. 爬山算法实现很简单,其主要缺点是会陷入局部最优解,而不一定能搜索到全局最优解.如图1所示:假设C点为当前解,爬山算法搜索到A点这个局部最优解就会停止搜索,因为在A点无论向那个方向小幅度移动都不能得到更优的解. 图1 二. 模

POJ 1379 模拟退火算法

求规定平面上一点到已知点的最小距离最大的点. 模拟退火的流程是,随机构造几组解作为初始解空间,每次对当前解空间进行随机扩展,若发现更优解则替换. 进行的次数由参数人为控制,而随机扩展的幅度也是随着次数逐渐减小的. #include<iostream> #include<cstdio> #include<cstring> #include<queue> #include<cmath> #include<string> #include&

hdu 4862 KM算法 最小K路径覆盖的模型

http://acm.hdu.edu.cn/showproblem.php?pid=4862 选t<=k次,t条路要经过所有的点一次并且仅仅一次, 建图是问题: 我自己最初就把n*m 个点分别放入X集合以及Y集合,再求最优匹配,然后连样例都过不了,而且其实当时解释不了什么情况下不能得到结果,因为k此这个条件相当于没用上... 建图方法: 1.X集合和Y集合都放入n*m+k个点,X中前n*m个点和Y中前n*m个点之间,如果格子里的值相等,权就是(收益-耗费),不等就是(-耗费),因为要的是最大收益

模拟退火算法简介

优化算法入门系列文章目录(更新中): 1. 模拟退火算法 2. 遗传算法 一. 爬山算法 ( Hill Climbing ) 介绍模拟退火前,先介绍爬山算法.爬山算法是一种简单的贪心搜索算法,该算法每次从当前解的临近解空间中选择一个最优解作为当前解,直到达到一个局部最优解. 爬山算法实现很简单,其主要缺点是会陷入局部最优解,而不一定能搜索到全局最优解.如图1所示:假设C点为当前解,爬山算法搜索到A点这个局部最优解就会停止搜索,因为在A点无论向那个方向小幅度移动都不能得到更优的解. 图1