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 个线段找到交点个数 思路:数据量小,直接暴力判断所有线段是否相交 /*************************************************** ...
随机推荐
- react基础篇三
事件处理 React事件绑定属性的命名采用驼峰式写法,而不是小写. 如果采用 JSX 的语法你需要传入一个函数作为事件处理函数,而不是一个字符串(DOM元素的写法) 例如,传统的 HTML: < ...
- HDU_5724_状态压缩的sg函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5724 题目大意:n行20列的棋盘,对于每行,如果当前棋子右边没棋子,那可以直接放到右边,如果有就跳过放 ...
- Repeater + 分页控件 AspNetPager 研究
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs ...
- Python匿名函数/排序函数/过滤函数/映射函数/递归/二分法
一. lamda匿名函数 为了解决一些简单的需求而设计的一句话函数 # 计算n的n次方 def func(n): return n**n print(func(10)) f = lambda n: n ...
- vue 导航菜单默认子路由
export default new Router({ routes: [ { path: '/', name: 'index', component: index, children: [ { pa ...
- 物理cpu与逻辑cpu概述
物理cpu与逻辑cpu概述(本博客属于转载部分内容:主要学习目的用于大数据平台Hadoop之yarn资源调度的配置) 一.yarn资源调度器中主要的资源分类 1.memory(内存) 2. ...
- javascript 数组 常用方法
前言 学学忘忘 闲来做个笔记 整理下数组常用方法. Array 数组常用方法 创建数组的基本方式有两种 1.第一种是使用Array构造函数, var arr = new Array(); ...
- leetcode 188-maxProfit
public static int maxProfit(int k, int[] prices) { if (0 >= k || null == prices || 1 >= prices ...
- grunt入门 出处:http://artwl.cnblogs.com
grunt-contrib-uglify uglify是一个文件压缩插件,项目地址:https://github.com/gruntjs/grunt-contrib-uglify 本文将以一个DEMO ...
- 7.IDEA创建Web项目和Tomcat配置
IntelliJ IDEA Tomcat配置 详解 Tomcat 7.0 和jdk1.8 一起使用 一.创建web项目 1.1 创建工程 1.2 创建java web项目并创建web.xml文件 1 ...