Buried memory
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4067 Accepted Submission(s): 2171
Problem Description
Each person had do something foolish along with his or her growth.But,when he or she did this that time,they could not predict that this thing is a mistake and they will want this thing would rather not happened.
The world king Sconbin is not the exception.One day,Sconbin was sleeping,then swakened by one nightmare.It turned out that his love letters to Dufein were made public in his dream.These foolish letters might ruin his throne.Sconbin decided to destroy the letters by the military exercises's opportunity.The missile is the best weapon.Considered the execution of the missile,Sconbin chose to use one missile with the minimum destruction.
Sconbin had writen N letters to Dufein, she buried these letters on different places.Sconbin got the places by difficult,he wants to know where is the best place launch the missile,and the smallest radius of the burst area. Let's help Sconbin to get the award.
Input
There are many test cases.Each case consists of a positive integer N(N<500,^V^,our great king might be a considerate lover) on a line followed by N lines giving the coordinates of N letters.Each coordinates have two numbers,x coordinate and y coordinate.N=0 is the end of the input file.
Output
For each case,there should be a single line in the output,containing three numbers,the first and second are x and y coordinates of the missile to launch,the third is the smallest radius the missile need to destroy all N letters.All output numbers are rounded to the second digit after the decimal point.
Sample Input
3
1.00 1.00 2.00
2.00 3.00 3.00
0
Sample Output
2.00 2.00 1.41
做法类似POJ2069
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 using namespacestd;15 #define it iterator
16 #define ll long long
17 #define eb emplace_back
18 #define lowbit(x) x & -x
19 #define all(x) x.begin(),x.end()
20 #define ZERO(a) memset(a,0,sizeof(a))
21 #define MINUS(a) memset(a,0xff,sizeof(a))
22 #define per(x,a,b) for(int x = a; x <= b; x++)
23 #define rep(x,a,b) for(int x = a; x >= b; x--)
24 #define IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
25
26 const int birth = 19260817;27 const int mo = 998244353;28 const int maxn = 1e5 + 10;29 const int mod = 1e9 + 7;30 const int INF = 0x3fffffff;31 const double eps = 1e-8;32
33 //******************THE PROGRAM BEGINING******************
34 structnode35 {36 doublex, y;37 }p[510],now;38
39 doubledis(node a, node b)40 {41 return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));42 }43
44 double solve(intn)45 {46 doubleans, cmp;47 double T = 100.0;48 double delat = 0.98;49 now.x = now.y = 0.0;50 int pos = 0;51 while (T >eps)52 {53 pos = 0;54 ans =dis(now, p[pos]);55 per(i, 0, n - 1)56 {57 cmp =dis(now, p[i]);58 if (cmp >ans)59 {60 pos =i;61 ans =cmp;62 }63 }64 now.x += (p[pos].x - now.x) / ans *T;65 now.y += (p[pos].y - now.y) / ans *T;66 T *=delat;67 }68 returnans;69 }70
71 intmain()72 {73 intn;74 while (scanf("%d", &n) &&n)75 {76 per(i, 0, n - 1)77 scanf("%lf %lf", &p[i].x, &p[i].y);78 double ans =solve(n);79 printf("%.2lf %.2lf %.2lf\n", now.x, now.y, ans);80 }81 return 0;82 }