题目链接: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. 测开之路二十九:Flask基础之jinja2模板

    中文文档:http://docs.jinkan.org/docs/jinja2/ 与静态资源一样,Flask默认的模板目录名为templates,如果有需要的话和static一样,要在初始化的时候声明 ...

  2. 用Linux 搭建 PXE 网络引导环境

    本例子中使用了CentOS7.4 minimal 系统,并且关闭了防火墙和selinux,并使用了dhcp.tftp.http和samba服务. 假设PXE服务器是192.168.4.104 ,tft ...

  3. appium常见问题09_MAC打开uiautimatorviewer闪退怎么办?

    问题: 下载安装Android SDK后,并且已在.bash_profile文件中配置环境变量.但是在tools中打开定位工具uiautomatorviewer出现闪退. 解决: 首先检查环境变量配置 ...

  4. 1.如何在JMeter中使用JUnit

    您是否需要在测试过程中使用JUnit? 要回答这个问题,我们先来看看单元测试. 单元测试是软件测试生命周期中测试的最低分辨率. 运行单元测试时,需要在应用程序中使用最小的可测试功能,将其与其他代码隔离 ...

  5. Cocos2d 之FlyBird开发---GameScore类

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. 这个类主要实现的是,显示历次成绩中的最好成绩.当然我写的这个很简洁,还可以写的更加的丰富.下面贴上代码: GameScore.h #ifn ...

  6. 【转】在配置静态IP的时候遇到 :bringing up interface eth0 : error unknown connection

    首先这是动态ip配置成功的结果 接下来切换到root用户来配置静态的 按照静态ip的配置方法配置好文件后(具体过程这里就不多加说明) 然后保存退出 当我们重启网卡的时候问题来了(因为本人有点强迫症,多 ...

  7. Python之字节到大整数的打包与解包

    需求:处理一个拥有128位长的16个元素的字节字符串 将bytes解析为整数,使用 int.from_bytes() 方法,并像下面这样指定字节顺序: # 为了将bytes解析为整数,使用 int.f ...

  8. 如何去掉万恶的wps屏保

    自从换了上个UI的电脑后,就莫名其妙的多了屏保,最开始以为屏蔽掉就好了,发现他依然不屈不挠的有,然后就百度了好多,也没找到...心累 今天终于开窍了,在角落里找打了.话不多说,上图 打开首页,找到应用 ...

  9. Mac 安装cnpm

    1.先安装node   node的下载地址:http://nodejs.cn/download/   这个没什么好说的,安装完成后测试一下,在终端输入:node -v   这时候就可以看到安装的nod ...

  10. mysql中查看所有表、表字段、表注释、字段注释

    查看所有表和表注释 select TABLE_NAME, TABLE_COMMENT from INFORMATION_SCHEMA.Tables where table_schema = '某数据库 ...