题面

题意:给你n个点,让你找到一个圆,输出圆心,和半径,使得有超过一半的点刚好在圆上.n<=1e5,题目保证了有解

题解:刚开始看着很不可做的样子,但是多想想,三点确定一个圆,三点啊!

现在有1/2的点都在圆上,意味着很多选出来的3个点都会导致同样的结果啊

我们同时可以说,每次随机一个点,这个点在圆上的概率为1/2,那任意三个点同时在圆上的概率就是1/8

所以我们随机来个几万次就好了啊!

注意的就是点数<=4的时候,1的时候输出自己就可以了,2,3,4的时候随便输出2个点的中点就行了

 #include<bits/stdc++.h>
using namespace std;
struct point
{
double x,y;
}a[],pp;
int T,n,x,y,z;
#define eps 1e-10
double R;
point cit(point a,point b,point c)
{
point cp;
double a1=b.x-a.x,b1=b.y-a.y,c1=(a1*a1+b1*b1)/;
double a2=c.x-a.x,b2=c.y-a.y,c2=(a2*a2+b2*b2)/;
double d=a1*b2-a2*b1;
cp.x=a.x+(c1*b2-c2*b1)/d;
cp.y=a.y+(a1*c2-a2*c1)/d;
return cp;
}
double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int ok(point p)
{
int tot=;
for (int i=;i<=n;i++)
{
if (fabs(dis(p,a[i])-R)<eps) tot++;
if (tot>=(n+)/) return ;
}
return ;
}
int kk(point x,point y,point z)
{
if ((x.x-y.x)*(x.y-z.y)==(x.y-y.y)*(x.x-z.x)) return ;
return ;
}
int main()
{
srand(time());
scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
for (int i=;i<=n;i++) scanf("%lf%lf",&a[i].x,&a[i].y);
if (n==)
{
printf("%lf %lf 0\n",a[].x,a[].y);
continue;
}
if (n<=)
{
pp.x=(a[].x+a[].x)/;
pp.y=(a[].y+a[].y)/;
printf("%lf %lf %lf\n",pp.x,pp.y,dis(pp,a[]));
continue;
}
for (int i=;i<=;i++)
{
x=rand()*rand()%n+;
y=rand()*rand()%n+;
z=rand()*rand()%n+;
if (x==y || y==z || x==z) continue;
if (kk(a[x],a[y],a[z])) continue;
pp=cit(a[x],a[y],a[z]);
R=dis(pp,a[x]);
if (ok(pp))
{
printf("%lf %lf %lf\n",pp.x,pp.y,R);
break;
}
}
}
}

Hdu-6242 2017CCPC-哈尔滨站 M.Geometry Problem 计算几何 随机的更多相关文章

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

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

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. hdu 1086 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/3 ...

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

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

  7. HDU - 6231 K-th Number (2017CCPC哈尔滨站 二分+尺取法)

    Alice are given an array A[1..N] with N numbers. Now Alice want to build an array B by a parameter K ...

  8. hdu 1086 You can Solve a Geometry Problem too [线段相交]

    题目:给出一些线段,判断有几个交点. 问题:如何判断两条线段是否相交? 向量叉乘(行列式计算):向量a(x1,y1),向量b(x2,y2): 首先我们要明白一个定理:向量a×向量b(×为向量叉乘),若 ...

  9. HDU 1086 You can Solve a Geometry Problem too( 判断线段是否相交 水题 )

    链接:传送门 题意:给出 n 个线段找到交点个数 思路:数据量小,直接暴力判断所有线段是否相交 /*************************************************** ...

随机推荐

  1. python2打印list中文内容防乱码

    zh_ls = ['人','民'] print str(zh_ls).decode("string_escape")

  2. JavaOO知识点小结一

    Java语言的特点是什么?简单 面向对象 跨平台 多线程 健壮性安全性 垃圾回收机制如何编译和执行java文件?产生帮助文档用什么命令?编译: javac 文件名执行: java 类名产生帮助文档 j ...

  3. Java_Jdbc_连接mysql数据库_1.打通数据库

    准备工作:myeclipes,mysql,navicat,jar包等工具 首先,需要导入连接数据库需要的jar包.照着教程敲的程序一直出错,结果就是导jar包导得有问题. 正确的(不唯一)的步骤为:1 ...

  4. node mysql es6/es7改造

    本文js代码采取了ES6/ES7的写法,而不是commonJs的写法.支持一波JS的新语法.node版本的mysql驱动,通过npm i mysql安装.官网地址:https://github.com ...

  5. PAT_A1149#Dangerous Goods Packaging

    Source: PAT A1149 Dangerous Goods Packaging (25 分) Description: When shipping goods with containers, ...

  6. 【剑指Offer】11、二进制中1的个数

      题目描述:   输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示.   解题思路:   本题有以下两个解决方案:   (1)依次判断每一位.判断的方法是先与1相与,为1则说明该位为1 ...

  7. C#第十二节课

    数组 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Th ...

  8. 单行函数、表连接(day02)

    回顾: 1.数据库介绍 sql: dql: select dml: insert delete update ddl: create drop alter tcl: commit rollback s ...

  9. nyoj29-求置转换问题

    求转置矩阵问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 求一个三行三列的转置矩阵. 输入 第一行一个整数n<20,表示有n组测试数据,下面是n组数据;每组测 ...

  10. 常用rides命令

    rides使用步骤 1.源代码构建安装 1.下载,Linux下命令wget http://redis.io/download下载redis的包 2.解归档Linux下命令tar -xvf redis- ...