HDU-6242:Geometry Problem(随机化+几何)

 

                                           Geometry Problem

                                     Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
                                                         Total Submission(s): 1587    Accepted Submission(s): 288
                                                                                       Special Judge

 

Problem Description

Alice is interesting in computation geometry problem recently. She found a interesting problem and solved it easily. Now she will give this problem to you :

You are given N distinct points (Xi,Yi) on the two-dimensional plane. Your task is to find a point P and a real number R, such that for at least ⌈N2⌉ given points, their distance to point P is equal to R.

 

 

Input

The first line is the number of test cases.

For each test case, the first line contains one positive number N(1≤N≤10^5).

The following N lines describe the points. Each line contains two real numbers Xi and Yi (0≤|Xi|,|Yi|≤10^3) indicating one give point. It's guaranteed that N points are distinct.

 

 

Output

For each test case, output a single line with three real numbers XP,YP,R, where (XP,YP) is the coordinate of required point P. Three real numbers you output should satisfy 0≤|XP|,|YP|,R≤10^9.

It is guaranteed that there exists at least one solution satisfying all conditions. And if there are different solutions, print any one of them. The judge will regard two point's distance as R if it is within an absolute error of 10−3 of R.

 

Sample Input

1

7

1 1

1 0

1 -1

0 1

-1 1

0 -1

-1 0

Sample Output

0 0 1

 

思路:从n个点中随机3个点求出其共圆的圆心,判断其是否满足条件。

 

#include
using namespace std;
const int MAX=2e5;
struct Point
{
    double x,y;
}p[MAX];
double dis(Point a,Point b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
Point solve(Point a,Point b,Point c)//三点共圆圆心公式
{
    double x=( (a.x*a.x-b.x*b.x+a.y*a.y-b.y*b.y)*(a.y-c.y)-(a.x*a.x-c.x*c.x+a.y*a.y-c.y*c.y)*(a.y-b.y) ) / (2*(a.y-c.y)*(a.x-b.x)-2*(a.y-b.y)*(a.x-c.x));
    double y=( (a.x*a.x-b.x*b.x+a.y*a.y-b.y*b.y)*(a.x-c.x)-(a.x*a.x-c.x*c.x+a.y*a.y-c.y*c.y)*(a.x-b.x) ) / (2*(a.y-b.y)*(a.x-c.x)-2*(a.y-c.y)*(a.x-b.x));
    return (Point){x,y};
}
int main()
{
    int T,n;cin>>T;
    while(T--)
    {
        scanf("%d",&n);
        for(int i=0;i=n){printf("%lf %lf %lf\n",q.x,q.y,dis(p[a],q));break;}
        }
    }
    return 0;
}

 

你可能感兴趣的:(计算几何,ACM)