1
/**//**************************************
2
Problem: HEU 1003 A Star not a Tree?
3
Time: 0.0040 s
4
Memory: 260 k
5
Accepted Time: 2009-03-25 11:10:32
6
Tips: 别人的再好,也不是自己的!http://hi.baidu.com/novosbirsk/blog/item/75983f138499f825dd54019b%2Ehtml
7
**************************************/
8
#include <cstdio>
9
#include <cmath>
10
#define PRECISION 1e-8
11
#define N 101
12
struct POINT
{
13
double x, y;
14
15
POINT(double x, double y) :
16
x(x), y(y)
{
17
}
18
19
POINT() :
20
x(0), y(0)
{
21
}
22
};
23
POINT plist[N];
24
25
inline double sqr(double x)
{
26
return x * x;
27
}
28
29
double pt_distance(const POINT &p1, const POINT &p2)
{
30
return sqrt(sqr(p1.x - p2.x) + sqr(p1.y - p2.y));
31
}
32
double get_all_dis(const POINT &p, int n)
{
33
double ans = 0.0;
34
for (int i = 0; i < n; i++)
35
ans += pt_distance(plist[i], p);
36
return ans;
37
}
38
39
int main()
{
40
int i, n;
41
scanf("%d", &n);
42
for (i = 0; i < n; i++)
43
scanf("%lf%lf", &plist[i].x, &plist[i].y);
44
POINT st = plist[0];
45
double step = 100, mind = get_all_dis(st, n);
46
while (step > 0.2)
{
47
int ok = 1;
48
while (ok)
{
49
POINT tmp, nt;
50
double t;
51
ok = 0,nt = st;
52
tmp = POINT(st.x, st.y + step);
53
t = get_all_dis(tmp, n);
54
if (t < mind)
55
mind = t, ok = 1, nt = tmp;
56
57
tmp = POINT(st.x, st.y - step);
58
t = get_all_dis(tmp, n);
59
if (t < mind)
60
mind = t, ok = 1, nt = tmp;
61
62
tmp = POINT(st.x + step, st.y);
63
t = get_all_dis(tmp, n);
64
if (t < mind)
65
mind = t, ok = 1, nt = tmp;
66
67
tmp = POINT(st.x - step, st.y);
68
t = get_all_dis(tmp, n);
69
if (t < mind)
70
mind = t, ok = 1, nt = tmp;
71
st = nt;
72
}
73
step = step / 2.0;
74
}
75
int ans = (int) (mind + 0.5) * 100 / 100;
76
printf("%d\n", ans);
77
getchar();getchar();
78
return 0;
79
}
80


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
