BZOJ 2210: Pku1379 Run Away 模拟退火
来源:互联网 发布:四方麻将 河南软件 编辑:程序博客网 时间:2024/06/11 03:01
2210: Pku1379 Run Away
Time Limit: 1 Sec Memory Limit: 259 MBSubmit: 141 Solved: 54
[Submit][Status][Discuss]
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
3
1000 50 1
10 10
100 100 4
10 10
10 90
90 10
90 90
3000 3000 4
1200 85
63 2500
2700 2650
2990 100
1000 50 1
10 10
100 100 4
10 10
10 90
90 10
90 90
3000 3000 4
1200 85
63 2500
2700 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).
The safest point is (50.0, 50.0).
The safest point is (1433.0, 1669.8).
随机大法好。。
#include<cmath>#include<ctime>#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>#include<iomanip>#include<vector>#include<string>#include<bitset>#include<queue>#include<set>#include<map>using namespace std;typedef long long ll;typedef double db;inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return f*x;}void print(int x){if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}const int N=1010;;const db pi=acos(-1),eps=1e-3,inf=1e20;struct node{db x,y,dis;}p[N];db x[N],y[N];inline db getdis(db x,db y,db x2,db y2){return sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));}int main(){register int T=read(),X,Y,n,i,j,k,P=15,L=25;srand(2018);while(T--){X=read();Y=read();n=read();db delta=db(max(X,Y))/sqrt(n);for(i=1;i<=n;++i)scanf("%lf%lf",&x[i],&y[i]);for(i=1;i<=P;++i){p[i].x=db(rand()%1000+1)/1000.0*X;p[i].y=db(rand()%1000+1)/1000.0*Y;p[i].dis=inf;for(j=1;j<=n;++j)p[i].dis=min(p[i].dis,getdis(p[i].x,p[i].y,x[j],y[j]));}while(delta>eps){for(i=1;i<=P;++i){node tmp=p[i];for(j=1;j<=L;++j){db theta=db(rand()%1000+1)/1000.0*10*pi;node t;t.x=tmp.x+cos(theta)*delta;t.y=tmp.y+sin(theta)*delta;if(t.x<0||t.y<0||t.x>X||t.y>Y)continue;t.dis=inf;for(k=1;k<=n;++k)t.dis=min(t.dis,getdis(t.x,t.y,x[k],y[k]));if(t.dis>p[i].dis)p[i]=t;}}delta*=0.8;}k=1;for(i=2;i<=P;++i)if(p[i].dis>p[k].dis)k=i;printf("The safest point is (%.1lf, %.1lf).\n",p[k].x,p[k].y);}return 0;}
阅读全文
0 0
- BZOJ 2210: Pku1379 Run Away 模拟退火
- 【模拟退火】 poj1379 Run Away
- 【POJ1379】Run Away 模拟退火
- 模拟退火 hdu1109 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(模拟退火)
- 模拟退火算法(run away poj1379)
- poj 1379 Run Away 模拟退火
- POJ 1379 Run Away 模拟退火
- POJ 1379 run away 模拟退火算法
- HDU 1109 Run Away 模拟退火算法
- 【HDU 1109 Run Away 模拟退火算法】
- 模拟退火 poj3422 run away
- 一种优秀的放置枚举的编码方式
- 杭电1000 A + B Problem
- IP网络协议
- vuejs组件之slot内容分发实例详解
- 5. Longest Palindromic Substring
- BZOJ 2210: Pku1379 Run Away 模拟退火
- 杭电1001 Sum Problem
- 算法笔记:使用栈实现汉诺塔(Hanoi)经典算法
- 垃圾收集与分配策略——(三)HotSpot的算法实现
- Java注解
- QWT的配置和使用(1)
- java递归浅析合并排序
- 杭电1002 A + B Problem II
- 机器学习之旅:数据预处理的对象-数据