HDU 3932 Groundhog Build Home (随机算法)

HDU3932 随机大法乱搞!

Groundhog Build Home

Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1579 Accepted Submission(s): 686

Problem Description

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 build its own home.xiaomi like to visit other family so much, at each visit it always start from the point of his own home.Xiaomi will visit all of the groundhogs’ home in this area(it will chose the linear distance between two homes).To save energy,xiaomi would like you to help it find where its home built,so that the longest distance between xiaomi’s home and the other groundhog’s home is minimum.

Input

The input consists of many test cases,ending of eof.Each test case begins with a line containing three integers X, Y, N separated by space.The numbers satisfy conditions: 1 <= X,Y <=10000, 1 <= N<= 1000. Groundhogs acivity at a rectangular area ,and X, Y is the two side of this rectangle, The number N stands for the number of holes.Then exactly N lines follow, each containing two integer numbers xi and yi (0 <= xi <= X, 0 <= yi <= Y) indicating the coordinates of one home.

Output

Print exactly two lines for each test case.The first line is the coordinate of xiaomi’s home which we help to find. The second line is he longest distance between xiaomi’s home and the other groundhog’s home.The output round to the nearest number with exactly one digit after the decimal point (0.05 rounds up to 0.1).

Sample Input

1000 50 1 10 10 1000 50 4 0 0 1 0 0 1 1 1

Sample Output

(10.0,10.0). 0.0 (0.5,0.5). 0.7

Source

2011 Multi-University Training Contest 10 - Host by HRBEU

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <stdio.h>

#include <string.h>

#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <string>

#include <math.h>

#include <stdlib.h>

#include <time.h>

using namespace std;

const int MAXN = 10100;

const double PI = acos(-1.0);

struct Point{

double x,y;

void input(){

scanf("%lf%lf",&x,&y);

}

double distance(Point b){

return sqrt((x-b.x)(x-b.x)+(y-b.y)(y-b.y));

}

}p[MAXN],tp[50];

double dist[50];

int n;

double calc(Point p0){

double ret = 0;

for(int i = 0;i < n;i++)

ret = max(ret,p[i].distance(p0));

return ret;

}

int main()

{

//freopen("in.txt","r",stdin);

//freopen("out.txt","w",stdout);

double X,Y;

srand(time(NULL));

int P = 15, L = 30;

while(scanf("%lf%lf%d",&X,&Y,&n) == 3){

for(int i = 0;i < n;i++)p[i].input();

for(int i = 0;i < P;i++){

tp[i].x = (rand()%1000+1)/1000.0*X;

tp[i].y = (rand()%1000+1)/1000.0*Y;

dist[i] = calc(tp[i]);

}

double step = sqrt(X*X + Y*Y)/2;

while(step > 1e-5){

for(int i = 0;i < P;i++){

Point cur, pre = tp[i];

for(int j = 0;j < L;j++){

double angle = (rand()%1000+1)/1000.0*2*PI;

cur.x = pre.x + cos(angle)*step;

cur.y = pre.y + sin(angle)*step;

if(cur.x < 0 || cur.x > X || cur.y < 0 || cur.y > Y)continue;

double tmp = calc(cur);

if(tmp < dist[i]){

tp[i] = cur;

dist[i] = tmp;

}

}

}

step *= 0.85;

}

int id;

double ans = 1e20;

for(int i = 0;i < P;i++)

if(dist[i] < ans){

ans = dist[i];

id = i;

}

printf("(%.1lf,%.1lf).\n",tp[id].x,tp[id].y);

printf("%.1lf\n",dist[id]);

}

return 0;

}
------ 本文结束------
  • 本文作者: kuangbin
  • 本文链接: 435.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
0%