Buried memory
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
解题思路:
模拟退火板子题。
AC代码:
//#include <bits/stdc++.h>
#include <math.h>
#include <cstdio>
#include <iostream>
#include <cstring>
#define int long long
using namespace std;
const int mod = 1e9+7;
struct node{
double x,y;
}p[100005];
int n;
double dis(double xx,double yy,int i){
double x = xx-p[i].x;
double y = yy-p[i].y;
return sqrt(x*x+y*y);
}
double sa(){
double EPS = 1e-12;
double T = 10000;
double delta = 0.98;
double res = 1e18;
double x = 0,y = 0,z = 0;
while(T > EPS){
double diss = 0;
int d = 0;
for(int i = 0 ; i < n ; i ++){
double tmp = dis(x,y,i);
if(tmp > diss){
diss = tmp;
d = i;
}
}
res = min(res,diss);
x += (p[d].x - x)/diss*delta*T;
y += (p[d].y - y)/diss*delta*T;
T *= delta;
}
printf("%.2f %.2f %.2f\n",x,y,res);
return res;
}
signed main(){
while(~scanf("%lld",&n) && n){
for(int i = 0 ; i < n ; i ++)
scanf("%lf%lf",&p[i].x,&p[i].y);
sa();
}
return 0;
}