poj 1379 Run Away 模拟退火
来源:互联网 发布:华客 数据恢复 合肥 编辑:程序博客网 时间:2024/06/11 15:48
Run Away
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 7520 Accepted: 2280
Description
One of the traps we will encounter in the Pyramid is located in the Large Room. A lot of small holes are drilled into the floor. They look completely harmless at the first sight. But when activated, they start to throw out very hot java, uh ... pardon, lava. Unfortunately, all known paths to the Center Room (where the Sarcophagus is) contain a trigger that activates the trap. The ACM were not able to avoid that. But they have carefully monitored the positions of all the holes. So it is important to find the place in the Large Room that has the maximal distance from all the holes. This place is the safest in the entire room and the archaeologist has to hide there.
Input
The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing three integers X, Y, M separated by space. The numbers satisfy conditions: 1 <= X,Y <=10000, 1 <= M <= 1000. The numbers X and Yindicate the dimensions of the Large Room which has a rectangular shape. The number M stands for the number of holes. Then exactly M lines follow, each containing two integer numbers Ui and Vi (0 <= Ui <= X, 0 <= Vi <= Y) indicating the coordinates of one hole. There may be several holes at the same position.
Output
Print exactly one line for each test case. The line should contain the sentence "The safest point is (P, Q)." where P and Qare the coordinates of the point in the room that has the maximum distance from the nearest hole, rounded to the nearest number with exactly one digit after the decimal point (0.05 rounds up to 0.1).
Sample Input
31000 50 110 10100 100 410 1010 9090 1090 903000 3000 41200 8563 25002700 2650 2990 100
Sample Output
The safest point is (1000.0, 50.0).The safest point is (50.0, 50.0).The safest point is (1433.0, 1669.8).题意:在一个范围内给出一些点,找出一个点,使得这个点到它最近点的距离最大。
思路:模拟退火。
代码:
#include <cstdio>#include <cmath>#include <ctime>#include <cstdlib>#include <algorithm>using namespace std;#define eps 1e-6#define maxn 1000+10#define inf 1e20#define PI acos(-1.0)double X,Y;double x[maxn],y[maxn];double px[maxn],py[maxn],d[maxn];int n;double dist(double x1,double y1,double x2,double y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}int main(){int T;scanf("%d",&T);//srand(time(NULL));while(T--){scanf("%lf %lf %d",&X,&Y,&n);for(int i=0;i<n;i++){scanf("%lf %lf",&x[i],&y[i]);}px[0] = 0.0, py[0] = 0.0;px[1] = 0.0, py[1] = Y;px[2] = X, py[2] = 0.0;px[3] = X, py[3] = Y; for(int i=0;i<30;i++){if(i>=4){px[i] = (rand()%10005+1)/10005.0*X;py[i] = (rand()%10005+1)/10005.0*Y;}double t = inf;for(int j=0;j<n;j++){t = min(t,dist(px[i],py[i],x[j],y[j]));}d[i] = t;}double delta = max(X,Y)/sqrt(1.0*n);while(delta>eps){for(int i=0;i<30;i++){for(int j=0;j<10;j++){double a = (rand()%10005+1)/10005.0*2*PI;double dx = px[i] + delta*cos(a);double dy = py[i] + delta*sin(a);if(dx<0 || dx>X || dy<0 || dy>Y) continue;double t = inf;for(int k=0;k<n;k++){t = min(t,dist(dx,dy,x[k],y[k]));}if(t>d[i]) {d[i] = t;px[i] = dx;py[i] = dy;}}}delta *= 0.85;}double ans = 0.0;int q = 0;for(int i=0;i<30;i++){if(d[i]>ans){ans = d[i];q = i;}}printf("The safest point is (%.1f, %.1f).\n",px[q],py[q]);}return 0;}
0 0
- POJ--1379[Run Away] 模拟退火
- 【POJ 1379 Run Away模拟退火】
- poj 1379 Run away 模拟退火
- POJ 1379 Run Away(基础模拟退火)
- poj 1379 Run Away(模拟退火)
- [poj 1379]Run Away[模拟退火]
- POJ 1379 Run Away(模拟退火)
- poj 1379 Run Away 模拟退火
- POJ 1379 Run Away 模拟退火
- POJ 1379 run away 模拟退火算法
- poj 1379 Run Away 计算几何 模拟退火
- POJ, 1379Run Away(模拟退火算法)
- [模拟退火 || Voronoi图] POJ 1379 Run Away
- 【模拟退火】 poj1379 Run Away
- 【POJ1379】Run Away 模拟退火
- 模拟退火 hdu1109 Run away
- POJ 1379 Run away & POJ 2420 A star not a Tree [模拟退火] [爬山算法]
- 模拟退火算法(run away poj1379)
- jQuery常用选择器汇总
- 第一个Cocos2d-JS游戏
- 用户管理
- 我的工作笔记之第一篇 (星云)
- test
- poj 1379 Run Away 模拟退火
- socket编程多客户端
- ofbiz 登录时默认进入一个指定的模块 - 把酒言欢 - 博客园
- TCP/IP协议 三次握手和四次挥手
- seo:sitemap
- 设置为/时增加/
- 整形 值传递 引用传递 指针传递
- SQL SPOOL脚本示例
- 结账页面