题目链接: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 ;
}

最新文章

  1. [OSG]矩阵运算
  2. WPF环境下多点触屏开发的一些经验(转)
  3. linux tar 解压文件时指定文件名
  4. 使用Navicat修改SQLite数据库提示:no such collation sequence: LOCALIZED
  5. js 更改head的title
  6. 【安卓面试题】Activity和Task的启动模式有哪些?每种含义是什么?举例说明各自的应用场景
  7. 在fedora20下面手动为自己的安装程序创建桌面图标
  8. IOS 学习笔记 2015-03-20 OC-数值类型
  9. Android数据库信息显示在listview上
  10. java中的执行顺序
  11. vue视频学习笔记07
  12. Hive 执行作业时报错 [ Diagnostics: File file:/ *** reduce.xml does not exist FileNotFoundException: File file:/ ]
  13. MySQL中select、insert、update批量操作语句
  14. dmi-ipmi
  15. 香蕉派 banana pi BPI-M3 八核开源硬件开发板
  16. Sqlserver Sequence操作
  17. linux下 C程序 参数和内存
  18. 渗透日常之 花式实战助你理解CSRF
  19. Implementing x / 6 Using Only Bit Manipulations
  20. 【贪心】Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) A. String Reconstruction

热门文章

  1. Hibernate中常用HQL
  2. Tex与PDF
  3. Android深度探索-卷1第三章心得体会
  4. VB - 操作符(含Is)
  5. 50-python基础-python3-列表-函数sorted() 对列表进行临时排序
  6. mySQL的表连接
  7. Cas 使用maven的overlay搭建开发环境 (二)
  8. Supervisor 在ubuntu系统下添加自启动
  9. SQL查询连续年份
  10. python 发送json数据操作实例分析 - python