题目链接: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. webbrowser 防止读取 缓存

    http://bbs.csdn.net/topics/240011502 引用 3 楼 kelei0017 的回复: Delphi(Pascal) codeprocedure TInformation ...

  2. docker 提示 Drive has not been shared 错误

    Creating laradock_docker-in-docker_1 ... Creating laradock_docker-in-docker_1 ... error ERROR: for l ...

  3. C++学习书籍推荐

    列出几本侯捷老师推荐的书1. C++程序员必备的书a) <C++ Programming Language> Bjarne Stroustrupb) <C++ Primer> ...

  4. c# Winform dev控件之ChartControl

    1.改变颜色 字体颜色 背景颜色 XYDiagram dia = chartControl1.Diagram as XYDiagram; dia.AxisX.Label.TextColor = Col ...

  5. python中深copy,浅copy与赋值语句的区别

    以下详细讲解:python深复制,浅复制与赋值语句的区别 1. '='赋值语句,常规复制只是将另一个变量名关联到了列表,并不进行副本复制,实例如下: var1=[12,35,67,91,101]var ...

  6. activiti 流程部署的各种方式

    流程资源可以是各种类型的文件,在启动流程或流程实例运行过程中会被读取.下面介绍常用的流程资源. 一.流程资源 流程定义文件:扩展名为bpmn20.xml和bpmn; 流程定义的图片:用BPMN2.0规 ...

  7. 【知识强化】第六章 应用层 6.3 文件传输协议FTP

    这节课我们来学习一下文件传输协议FTP. 我们知道一个文件的传输过程呢一定需要协议的规定,那在文件传送协议这一块呢有很多个协议.比较主要的两个一个是文件传送协议FTP,一个是简单文件传送协议TFTP. ...

  8. Anaconda基本命令

    创建环境 conda create --name bunnies python=3 astroid babel 列出所有环境 conda info --envs 或 conda env list 克隆 ...

  9. RPC服务治理框架(一)RPC技术

    一.RPC是什么 remote procedure call:远程过程调用 过程就是程序,像调用本地方法一样调用远程的过程 RPC采用Client-Server结构,通过request-respons ...

  10. org.zkoss.zul.Filedownload.java 源码

    /* Filedownload.java Purpose: Description: History: Mon Apr 16 09:29:44 2007, Created by tomyeh Copy ...