Buried memory(HDU-3007)

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

题意:多组数据,以 0 为结束,每组给出 n 个点的坐标,要求用一个最小的圆将这些点全部覆盖,求这个圆的圆心和半径

思路:

题目本质是给出 n 个点的坐标,然后求某个点,使得这个点到其他点的距离最小

虽然是一个计算几何的最小圆覆盖模板题,但可以利用爬山法或模拟退火来解决

我们利用爬山法,在设置好爬山法的参数后,然后提交看 RP 即可

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<int,int>
LL quickPow(LL a,LL b){ LL res=1; while(b){if(b&1)res*=a; a*=a; b>>=1;} return res; }
LL multMod(LL a,LL b,LL mod){ a%=mod; b%=mod; LL res=0; while(b){if(b&1)res=(res+a)%mod; a=(a<<=1)%mod; b>>=1; } return res%mod;}
LL quickMultPowMod(LL a, LL b,LL mod){ LL res=1,k=a; while(b){if((b&1))res=multMod(res,k,mod)%mod; k=multMod(k,k,mod)%mod; b>>=1;} return res%mod;}
LL quickPowMod(LL a,LL b,LL mod){ LL res=1; while(b){if(b&1)res=(a*res)%mod; a=(a*a)%mod; b>>=1; } return res; }
LL getInv(LL a,LL mod){ return quickPowMod(a,mod-2,mod); }
LL GCD(LL x,LL y){ return !y?x:GCD(y,x%y); }
LL LCM(LL x,LL y){ return x/GCD(x,y)*y; }
const double EPS = 1E-15;
const int MOD = 1000000000+7;
const int N = 1000+5;
const int dx[] = {0,0,1,-1,1,1,-1,-1};
const int dy[] = {1,-1,0,0,1,-1,1,-1};
using namespace std;

struct point {
    double x, y;
} node[N];
int n;
double getRes(double x1, double y1, double x2, double y2) { //获取两点距离
    return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
int getPos(double x,double y) {//比较答案并获取新坐标点
    int pos;//新坐标点
    double res = -INF;
    for (int i = 1; i <= n; i++) {
        double newRes = getRes(x, y, node[i].x, node[i].y);//获取新状态答案
        if (newRes > res) { //比较答案
            res = newRes; //更新结果
            pos = i; //记录新坐标点
        }
    }
    return pos;
}
double HC(double &x,double &y) {
    double T = 1;
    double ans = INF;
    while (T > EPS) {
        int pos = getPos(x,y);//获取下一状态的坐标
        ans = min(ans, getRes(x,y, node[pos].x,node[pos].y));//记录最小距离
        x = x + (node[pos].x - x) * T;//转移x状态
        y = y + (node[pos].y - y) * T;//转移y状态
        T *= 0.96;
    }
    return ans;
}
int main() {
    while (scanf("%d", &n) != EOF&&n) {
        double x=0, y=0;//初始状态
        for (int i = 1; i <= n; ++i) {
            scanf("%lf%lf", &node[i].x, &node[i].y);
            x += node[i].x;
            y += node[i].y;
        }
        x /= n;
        y /= n;
        double ans=HC(x,y);
        printf("%.2f %.2f %.2f\n", x, y, ans);
    }
    return 0;
}

 

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
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页