Run Away
来源:互联网 发布:ai编程算法基础 编辑:程序博客网 时间:2024/06/05 10:55
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 <algorithm>#include <iostream>#include <cstdlib>#include <limits.h>#include <cstring>#include <cstdio>#include <time.h>#include <cmath>#include <queue>#define P 0.6#define INF 0x7fffffffusing namespace std;const int N=1001;const int maxn=10;const int maxd=25;struct node{ double x; double y; double dis;}p[N],tr[maxn];int x,y,n;inline int max(int x,int y){ return x<y?y:x;}double get_dis(node t){ double mi=INT_MAX; for(int i=0;i<n;i++) { double dis=(t.x-p[i].x)*(t.x-p[i].x)+(t.y-p[i].y)*(t.y-p[i].y); if(dis<mi) mi=dis; } return mi;}node get_ans(){ node tmp; double t,t_min=(1e-2)*5,k1,k2; t=max(x,y)*1.0/sqrt(n*1.0); for(int i=0;i<maxn;i++) { tr[i].x=((rand()%1000+1)*1.0/1000.00)*x; tr[i].y=((rand()%1000+1)*1.0/1000.00)*y; tr[i].dis=get_dis(tr[i]); } while(t>t_min) { for(int i=0;i<maxn;i++) { for(int j=1;j<=maxd;j++) { k1=(double)(rand()%1000+1)*1.0/1000.00*t; k2=sqrt(t*t-k1*k1); if(rand()%2) k1*=-1; if(rand()%2) k2*=-1; tmp.x=tr[i].x+k1; tmp.y=tr[i].y+k2; if(tmp.x>=0&&tmp.x<=x&&tmp.y>=0&&tmp.y<=y) { tmp.dis=get_dis(tmp); if(tmp.dis>tr[i].dis) tr[i]=tmp; } } } t=t*P; } int max=0; for(int i=1;i<maxn;i++) { if(tr[i].dis>tr[max].dis) max=i; } return tr[max];}int main(){ int t; node ans; scanf("%d",&t); while(t--) { scanf("%d %d %d",&x,&y,&n); for(int i=0;i<n;i++) scanf("%lf %lf",&p[i].x,&p[i].y); ans=get_ans(); printf("The safest point is (%.1lf, %.1lf).\n",ans.x,ans.y); } return 0;}
- Run Away
- run away
- run away with me
- poj 1379 Run Away
- HOJ 1026 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
- hdu 1109 Run Away
- poj1379——Run Away
- 【模拟退火】 poj1379 Run Away
- 【POJ1379】Run Away 模拟退火
- 模拟退火 hdu1109 Run away
- POJ 1379 Run Away 笔记
- HDOJ HDU 1109 Run Away
- Groovy轻松入门——搭建Groovy开发环境
- STL_list的使用(转)
- linux图形栈
- c51 单片机实验_2 数码管
- Python学习(类)
- Run Away
- Erlang聊天程序后端(三)
- Run Loop
- netbeans常用快捷键
- 交叉编译CUPS
- 建造者模式lua实现
- 对手
- NSNotificationCenter的工作机制
- 矩形框绘制_运动检测_OpenCV