题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6242

思路:当 n == 1 时 任取一点 p 作为圆心即可。

    n >= 2 && n < 5 时 此时有可能出现所有点共线,所以取任意俩点间中点作为圆的圆心。

    n >= 5 保证了有解。所以不可能有所有点共线的情况,随机取三个点在正解圆上的概率是 1/8,还是蛮大的...。

    外学了下随机算法的写法....时间种子 time(0)要强制转成int,不然会WA,不造为啥....

AC代码:

 #include<bits/stdc++.h>
using namespace std;
const double eps = 1e-;
const double INF = 1e18;
const int maxn = 1e5 + ;
int sgn(double x)
{
if(fabs(x) < eps) return ;
else return x < ? - : ;
}
struct Point{
double x, y;
Point(){}
Point(double _x, double _y){
x = _x; y = _y;
}
void input()
{
scanf("%lf %lf", &x, &y);
}
bool operator ==(const Point &b) const{
return sgn(x - b.x) == && sgn(y - b.y) == ;
}
bool operator <(const Point &b) const{
return sgn(x - b.x) == ? sgn(y - b.y) < : x < b.x;
}
Point operator -(const Point &b) const{
return Point(x - b.x, y - b.y);
}
Point operator +(const Point &b) const{
return Point(x + b.x, y + b.y);
}
double operator ^(const Point &b) const{
return x*b.y - b.x*y;
}
double operator *(const Point &b) const{
return x*b.x + y*b.y;
}
Point operator*(const double &k)const{
return Point(x*k,y*k);
}
Point operator/(const double &k)const{
return Point(x/k,y/k);
}
Point rotleft(){
return Point(-y, x);
}
double distance(Point p)
{
return hypot(x - p.x,y - p.y);
}
} p[maxn];
struct Line{
Point s, e;
Line(){}
Line(Point _s, Point _e){
s = _s, e = _e;
}
Point crosspoint(Line v){
double a1 = (v.e - v.s) ^ (s - v.s);
double a2 = (v.e - v.s) ^ (e - v.s);
return Point((s.x*a2-e.x*a1)/(a2-a1),(s.y*a2-e.y*a1)/(a2-a1));
}
};
struct circle{
Point p;
double r;
circle(){}
circle(Point a, Point b, Point c){
Line u = Line( (a + b) / , ( (a + b) / ) + ( (b - a).rotleft() ));
Line v = Line( (b + c) / , ( (b + c) / ) + ( (c - b).rotleft() ));
p = u.crosspoint(v);
r = p.distance(a);
}
int relation(Point b){
double dst = b.distance(p);
if(sgn(dst - r)<) return ;
else if(sgn(dst - r) == ) return ;
return ;
}
};
int main()
{
int t;
scanf("%d",&t);
srand((int)time());
while(t--)
{
int n;
scanf("%d",&n);
for(int i = ;i < n;i++) p[i].input();
if(n == ) printf("0.000 0.000 %.6f\n",p[].distance(Point(,)));
else if(n >= && n < ){
Point v = (p[] + p[])/;
printf("%.6f %.6f %.6f\n", v.x, v.y, 0.5*p[].distance(p[]));
}
else{
while(){
int a = rand() % n, b = a, c = a;
while(b = rand() % n){
if(b != a) break;
}
while(c = rand() % n){
if(c != a && c != b) break;
}
circle C = circle(p[a], p[b], p[c]);
int num = ;
for(int i = ;i < n;i++)
{
if(C.relation(p[i]) == ) num++;
}
if(num >= (n + ) / ){
printf("%.6f %.6f %.6f\n",C.p.x ,C.p.y, C.r);
break;
}
}
}
}
return ;
}

HDU 6242 Geometry Problem(计算几何 + 随机化)的更多相关文章

  1. HDU - 6242 Geometry Problem (几何,思维,随机)

    Geometry Problem HDU - 6242 Alice is interesting in computation geometry problem recently. She found ...

  2. hdu 6242 Geometry Problem

    Geometry Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Other ...

  3. Codeforces Gym 100338B Geometry Problem 计算几何

    Problem B. Geometry ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

  4. Hdu-6242 2017CCPC-哈尔滨站 M.Geometry Problem 计算几何 随机

    题面 题意:给你n个点,让你找到一个圆,输出圆心,和半径,使得有超过一半的点刚好在圆上.n<=1e5,题目保证了有解 题解:刚开始看着很不可做的样子,但是多想想,三点确定一个圆,三点啊! 现在有 ...

  5. hdu 1086:You can Solve a Geometry Problem too(计算几何,判断两线段相交,水题)

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

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

    Alice is interesting in computation geometry problem recently. She found a interesting problem and s ...

  7. HDU 5572 An Easy Physics Problem (计算几何+对称点模板)

    HDU 5572 An Easy Physics Problem (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5572 Descripti ...

  8. hdu 1086 You can Solve a Geometry Problem too

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  9. (hdu step 7.1.2)You can Solve a Geometry Problem too(乞讨n条线段,相交两者之间的段数)

    称号: You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/ ...

随机推荐

  1. Java学习之线程间通信(双线程)

    线程间通讯:多个线程在处理同一资源,但是任务不同 练习一:双线程出现线程安全问题,需要使用同步,思考同步代码添加位置需求:银行账户存钱,显示谁在账户存钱了,存了多少钱分析:操作同一银行账户两个不同的操 ...

  2. ajax请求controller出现中文乱码

    ajax请求controller出现中文乱码 解决方法:在 @RequestMapping 中加上  produces = {"application/json;charset=UTF-8& ...

  3. (转)SQL注入原理

    原文地址:http://www.cnblogs.com/rush/archive/2011/12/31/2309203.html SQL Injection:就是通过把SQL命令插入到Web表单递交或 ...

  4. fiddler 解决不能抓https包的问题

    新解决方案 重置Fiddler,具体步骤: Tools > Fiddler Options > HTTPS > “Certificates generated by MakeCert ...

  5. python排序参数key以及lambda函数

    首先,lambda格式 lambda x:x+1, 前面的x相当于传入的形参,后面的相当于返回值, 使用起来很简单,只要明白“:”前后的含义即可正确使用. 再来说一下排序等函数中的key,这里以lis ...

  6. 逃脱 (简单BFS)

    题目传送门 G逃脱  题目描述 这是mengxiang000和Tabris来到幼儿园的第四天,幼儿园老师在值班的时候突然发现幼儿园某处发生火灾,而且火势蔓延极快,老师在第一时间就发出了警报,位于幼儿园 ...

  7. 获得本机物理ip地址mac

    https://blog.csdn.net/guang670248515/article/details/81040797 文章来源:https://blog.csdn.net/kingepoch/a ...

  8. 不修改源代码,动态注入Java代码的方法(转)

    转自:https://blog.csdn.net/hiphoon_sun/article/details/38707927 有时,我们需要在不修改源代码的前提下往一个第三方的JAVA程序里注入自己的代 ...

  9. GCC -l选项:手动添加链接库

    链接器把多个二进制的目标文件(object file)链接成一个单独的可执行文件.在链接过程中,它必须把符号(变量名.函数名等一些列标识符)用对应的数据的内存地址(变量地址.函数地址等)替代,以完成程 ...

  10. linux rsync 复制文件忽略文件夹

    比如: /home/vagrant/test 目录下有 a,b,c 三个文件夹,只复制 c 文件夹下面的文件到/home/vagrant/test2 下 使用cp命令复制的时候,只能排除一个目录不被复 ...