Hdu-6242 2017CCPC-哈尔滨站 M.Geometry Problem 计算几何 随机
题意:给你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 计算几何 随机的更多相关文章
- HDU - 6242:Geometry Problem(随机+几何)
Alice is interesting in computation geometry problem recently. She found a interesting problem and s ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Gym 100338B Geometry Problem 计算几何
Problem B. Geometry ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...
- 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 ...
- hdu 1086 You can Solve a Geometry Problem too [线段相交]
题目:给出一些线段,判断有几个交点. 问题:如何判断两条线段是否相交? 向量叉乘(行列式计算):向量a(x1,y1),向量b(x2,y2): 首先我们要明白一个定理:向量a×向量b(×为向量叉乘),若 ...
- HDU 1086 You can Solve a Geometry Problem too( 判断线段是否相交 水题 )
链接:传送门 题意:给出 n 个线段找到交点个数 思路:数据量小,直接暴力判断所有线段是否相交 /*************************************************** ...
随机推荐
- python特性小记(一)
一.关于构造函数和析构函数 1.python中有构造函数和析构函数,和其他语言是一样的.如果子类需要用到父类的构造函数,则需要在子类的构造函数中显式的调用,且如果子类有自己的构造函数,必然不会自动调用 ...
- vsftp服务器搭建
1.FTP的主动模式和被动模式的区别: 最大的区别是数据端口并不总是20, 主动模式和被动模式的优缺点: 主动FTP对FTP服务器的管理和安全很有利,但对客户端的管理不利.因为FTP服务器企图与客户端 ...
- XML、集合、JSP综合练习
一.利用DOM解析XML文件得到信息:存入泛型集合中在JSP页面循环打印读取的信息 a) 编写XML文件:添加测试节点数据 b) 建立web项目:在JSP页面中使用DO ...
- AdaBoost--从原理到实现(Code:Python)
本文对原文有修改,若有疑虑,请移步原作者. 原文链接:blog.csdn.net/dark_scope/article/details/14103983 集成方法在函数模型上等价于一个多层神经网络, ...
- ICCV2015上的GazeTracker论文总结
SLAM问题先慢慢编译一段时间,赶紧拾起来GazeTrack的事情...... ICCV2015的大部分paper已经可以下载,文章列表在这个位置. http://www.cvpapers.com/i ...
- 【sqli-labs】 less41 GET -Blind based -Intiger -Stacked(GET型基于盲注的堆叠查询整型注入)
整型的不用闭合引号 http://192.168.136.128/sqli-labs-master/Less-41/?id=1;insert into users(id,username,passwo ...
- Ubuntu 更换阿里源
查看新版本信息 lsb_release -c Ubuntu 12.04 (LTS)代号为precise. Ubuntu 14.04 (LTS)代号为trusty. Ubuntu 15.04 代号为vi ...
- MAMP PRO mysql无法启动
mac上可能勾选了软件自动更新,然后MAMP PRO 升级了. 升级了之后,mysql启动就出问题了,看报错日志: InnoDB: The error means the system cannot ...
- Java 各级注解及@Autowired注入为null解决办法
1.@controller 控制器 用于标注控制层,相当于struts中的action层. 2.@service 服务层 用于标注服务层,主要用来进行业务的逻辑处理. 3.@repository DA ...
- RabbitMQ出现服务启动几秒退出问题
最近在学习rebbitmq, 1.首先安装了otp_win64_20.3, 2.erlang安装完成需要配置erlang环境变量: 这个是新建的 文档是:ERLANG_HOME D:\develop\ ...