小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Buried memory

 印度阿三17 2021-03-14

Buried memory


來源:HDU - 3007


題目描述:

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.


輸入格式:

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.


輸出格式:

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.


輸入樣例:

3
1.00 1.00
2.00 2.00
3.00 3.00
0

輸出樣例:

2.00 2.00 1.41

思路:

典型的最小覆蓋圓問題,用求解最小覆蓋圓問題的算法解決即可。


AC代碼:

#include <bits/stdc  .h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

const int INF = 0x3f3f3f3f;
const int EPS = 1e-8;

void __init__ ()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

struct Point
{
    double x;
    double y;
};

int sgn (double x)
{
    if (fabs(x) < EPS) return 0;
    return x > 0 ? 1 : -1;
}

double distance (Point a, Point b)
{
    return hypot(a.x - b.x, a.y - b.y);
}

Point circle_center (Point a, Point b, Point c)
{
    Point center;
    double A1 = 2 * (b.x - a.x), B1 = 2 * (b.y - a.y), C1 = b.x * b.x   b.y * b.y - a.x * a.x - a.y * a.y;
    double A2 = 2 * (c.x - b.x), B2 = 2 * (c.y - b.y), C2 = c.x * c.x   c.y * c.y - b.x * b.x - b.y * b.y;
    center.x = (C1 * B2 - C2 * B1) / (A1 * B2 - A2 * B1);
    center.y = (C1 * A2 - C2 * A1) / (B1 * A2 - A1 * B2);
    return center;
}

void minus_cover_circle (vector<Point> p, Point& c, double& r)
{
    random_shuffle(p.begin(), p.end());
    c = p[0];
    r = 0;
    for (int i = 1; i < p.size(); i  )
    {
        if (sgn(distance(p[i], c) - r) > 0)
        {
            c = p[i];
            r = 0;
            for (int j = 0; j < i; j  )
            {
                if (sgn(distance(p[j], c) - r) > 0)
                {
                    c.x = (p[i].x   p[j].x) / 2;
                    c.y = (p[i].y   p[j].y) / 2;
                    r = distance(c, p[j]);
                    for (int k = 0; k < j; k  )
                    {
                        if (sgn(distance(p[k], c) - r) > 0)
                        {
                            c = circle_center(p[i], p[j], p[k]);
                            r = distance(c, p[k]);
                        }
                    }
                }
            }
        }
    }
}

vector<Point> p;

int main ()
{

    __init__();

    int n;
    Point c;
    double r;
    while (cin >> n && n)
    {
        p.resize(n);
        for (int i = 0; i < n; i  ) cin >> p[i].x >> p[i].y;
        minus_cover_circle(p, c, r);
        cout << fixed << setprecision(2) << c.x << " " << c.y << " " << r << endl;
    }

    return 0;
}
來源:https://www./content-4-891251.html

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多