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 个线段找到交点个数 思路:数据量小,直接暴力判断所有线段是否相交 /*************************************************** ...
随机推荐
- Android开发笔记(13)——ListFragment
转载请注明:http://www.cnblogs.com/igoslly/p/6959108.html ListFragment ListFragment是继承于Fragment的类,专门用于包含Li ...
- Android studio 添加引用新建类库
1.新建一个工程包 2.修改AndroidManifest.xml 将AndroidManifest.xml 修改为 <manifest xmlns:android="http://s ...
- SQL server基本语法
此处源于一个基本的SQL Server试题,基本上涵盖了SQL Server的全部基本语法,粘贴在此处,权当分享 --1. 创建TestDB数据库 create database TestDB; ...
- 如何在编辑器打开Java程序
我们都知道运行JAVA文件,可以从软件控制台运行我们写好的java文件,也可以从windows窗口运行,我们最开始接触的是通过windows窗口来运行java文件,下面简单介绍一下如何如何在编辑器打开 ...
- C# 带Cookies发送请求
#region --来自黄聪 void F1() { #region --创建cookies容器 添加Cookies和对应的URl(Hots主) CookieContainer cc = new Co ...
- 复习MySQL③导入数据、检查及修改
导入数据: 用insert into语句为表插入数据: - insert into 表名(字段1,字段2,…) values …… 导入外部文本文件: - 导入外部txt文件(导入CSV文件分隔符为' ...
- 死磕itchat源码--core.py
core.py文件中的Core类定义了itchat的所有接口.且,仅仅是定义了接口,全部在component包中实现重构.其用法如下表述: 缺省 源码如下: # -*- encoding: utf-8 ...
- PAT_A1127#ZigZagging on a Tree
Source: PAT A1127 ZigZagging on a Tree (30 分) Description: Suppose that all the keys in a binary tre ...
- 【剑指Offer】56、删除链表中重复的结点
题目描述: 在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针. 例如,链表1->2->3->3->4->4-> ...
- [kernel学习]----好文章梳理
内存相关 Linux的内存回收和交换 Linux内核分析:页回收导致的cpu load瞬间飙高的问题分析与思考 认识Linux物理内存回收机制 认真分析mmap:是什么 为什么 怎么用 kernel排 ...