HDU 3007 模拟退火算法
Posted qq965921539
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.
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 ", now.x, now.y, ans); 80 } 81 return 0; 82 }
以上是关于HDU 3007 模拟退火算法的主要内容,如果未能解决你的问题,请参考以下文章
HDU - 3644:A Chocolate Manufacturer's Problem(模拟退火, 求多边形内最大圆半径)