2017 CCPC 哈尔滨站 HDU 6242
Geometry Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1091 Accepted Submission(s): 208
Special Judge
You are given N distinct points (Xi,Yi) on the two-dimensional plane. Your task is to find a point P and a real number R, such that for at least ⌈N2⌉ given points, their distance to point P is equal to R.
For each test case, the first line contains one positive number N(1≤N≤105).
The following N lines describe the points. Each line contains two real numbers Xi and Yi (0≤|Xi|,|Yi|≤103) indicating one give point. It's guaranteed that Npoints are distinct.
It is guaranteed that there exists at least one solution satisfying all conditions. And if there are different solutions, print any one of them. The judge will regard two point's distance as R if it is within an absolute error of 10−3 of R.
题意 给出n个点 确定一个圆的圆心和半径 使得至少n/2个点(向上取整)在该圆上 对于每组样例至少有一个解
解析 我们知道 在n个点中每个点在圆上的概率都为0.5 三个不共线的点确定一个外接圆 我们随机取三个点 这三个点的外接圆满足条件的概率为0.5*0.5*0.5=0.125
每次随机消耗的时间复杂度为1e5 枚举1秒内可以100 次 基本可以得到答案
AC代码
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= 1e5+;
const double eps= 1e-;
const int inf = 0x3f3f3f3f;
typedef long long ll;
struct point
{
double x,y;
}a[maxn];
int n;
double dis(point a,point b) //两点间距离
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool waijie(point p1,point p2,point p3,point &ans) //引用修改圆心的值
{
if(fabs((p3.y-p2.y)*(p2.x-p1.x)-(p2.y-p1.y)*(p3.x-p2.x))<=eps)return false; //三点共线 没有外接圆
double Bx = p2.x - p1.x, By = p2.y - p1.y; //外接圆板子
double Cx = p3.x - p1.x, Cy = p3.y - p1.y;
double D = * (Bx * Cy - By * Cx);
double cx = (Cy * (Bx * Bx + By * By) - By * (Cx * Cx + Cy * Cy)) / D + p1.x;
double cy = (Bx * (Cx * Cx + Cy * Cy) - Cx * (Bx * Bx + By * By)) / D + p1.y;
ans.x=cx,ans.y=cy;
return true;
}
bool check(point mid,double d) //检查是否有n/2个点在外接圆上
{
int ans=;
for(int i=;i<=n;i++)
{
if(fabs(dis(a[i],mid)-d)<=eps)
ans++;
if((ans+(n-i))*<n) //简单优化一下 如果还未判断的点的数量加上已经满足条件的点的数量小于n/2 false
return false;
}
if(ans*>=n)
return true;
return false;
}
int main()
{
int t;
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<=) //n小于等于4特判
{
printf("%lf %lf %lf\n",a[].x,a[].y,0.0);
continue;
}
else if(n<=)
{
printf("%lf %lf %lf\n",(a[].x+a[].x)/,(a[].y+a[].y)/,dis(a[],a[])/);
continue;
}
while(true)
{
point aa=a[rand()%n+],bb=a[rand()%n+],cc=a[rand()%n+]; //随机产生3个点
point xin;
if(!waijie(aa,bb,cc,xin))
continue;
double r=dis(aa,xin);
if(check(xin,r))
{
// printf("%lf %lf\n",aa.x,aa.y);
// printf("%lf %lf\n",bb.x,bb.y);
// printf("%lf %lf\n",cc.x,cc.y);
printf("%lf %lf %lf\n",xin.x,xin.y,r);
break;
}
}
}
return ;
}
2017 CCPC 哈尔滨站 HDU 6242的更多相关文章
- HDU 6240 Server(2017 CCPC哈尔滨站 K题,01分数规划 + 树状数组优化DP)
题目链接 2017 CCPC Harbin Problem K 题意 给定若干物品,每个物品可以覆盖一个区间.现在要覆盖区间$[1, t]$. 求选出来的物品的$\frac{∑a_{i}}{∑b_ ...
- 2017 CCPC 哈尔滨站 题解
题目链接 2017 CCPC Harbin Problem A Problem B Problem D Problem F Problem L 考虑二分答案. 设当前待验证的答案为x 我们可以把第二 ...
- 2017 ccpc哈尔滨 A题 Palindrome
2017 ccpc哈尔滨 A题 Palindrome 题意: 给一个串\(T\),计算存在多少子串S满足\(S[i]=S[2n−i]=S[2n+i−2](1≤i≤n)\) 思路: 很明显这里的回文串长 ...
- HDU 6271 Master of Connected Component(2017 CCPC 杭州 H题,树分块 + 并查集的撤销)
题目链接 2017 CCPC Hangzhou Problem H 思路:对树进行分块.把第一棵树分成$\sqrt{n}$块,第二棵树也分成$\sqrt{n}$块. 分块的时候满足每个块是一个 ...
- HDU 6270 Marriage (2017 CCPC 杭州赛区 G题,生成函数 + 容斥 + 分治NTT)
题目链接 2017 CCPC Hangzhou Problem G 题意描述很清晰. 考虑每个家庭有且仅有$k$对近亲的方案数: $C(a, k) * C(b, k) * k!$ 那么如果在第$1$ ...
- HDU 6268 Master of Subgraph (2017 CCPC 杭州 E题,树分治 + 树上背包)
题目链接 2017 CCPC Hangzhou Problem E 题意 给定一棵树,每个点有一个权值,现在我们可以选一些连通的点,并且把这点选出来的点的权值相加,得到一个和. 求$[1, m] ...
- ccpc杭州站 赛后总结
Ccpc杭州站赛后总结 2017年11月4号五号,我参加了ccpc杭州站的比赛,我的队友是聂少飞和王艳,在4号一点半,举行了比赛开幕式,听着教练代表的发言,听着参赛选手代表的发言,听着志愿者的发言,都 ...
- ccpc 网络赛 hdu 6155
# ccpc 网络赛 hdu 6155(矩阵乘法 + 线段树) 题意: 给出 01 串,要么询问某个区间内不同的 01 子序列数量,要么把区间翻转. 叉姐的题解: 先考虑怎么算 \(s_1, s_2, ...
- 2017 多校3 hdu 6061 RXD and functions
2017 多校3 hdu 6061 RXD and functions(FFT) 题意: 给一个函数\(f(x)=\sum_{i=0}^{n}c_i \cdot x^{i}\) 求\(g(x) = f ...
随机推荐
- Mac_OS_Sierra_10.12.6编译OpenJDK9
编译环境以及依赖 macOS:Sierra,10.12.6 处理器:2.6 GHz Intel Core i7 内存:16 GB 2133 MHz LPDDR3 Command Line Tools ...
- 【原创】java NIO FileChannel 学习笔记 FileChannel 简介
java NIO 中FileChannel 的实现类是 FileChannelImpl,FileChannel本身是一个抽象类. 先介绍FileChannel File Channels 是线程安全 ...
- C# 字符串的连接
1.利用 "+"(加号)运算符: string str = "Hello"+ "World": console.WriteLine(str) ...
- pythonseleniumAPI
一.浏览器操作 1.浏览器最大化 driver.maximize_window() #将浏览器最大化显示 2.设置浏览器宽.高 driver.set_window_size(480, 800)#设置浏 ...
- Laravel 中实现是否关注
@if ($user->id !== Auth::user()->id) <div id="follow_form"> @if (Auth::user()- ...
- JSON 序列化和解析
概述 JSON 即 (Javascript Object Notation,Javascript 对象表示法),是在Javascript中写结构化数据的方式.而JSON本身只是一种数据格式. 通常开发 ...
- Emmet for Dreamweaver 整理分享
我是一名技术不是很到位的前端,每次做项目总要写大量的HTML和CSS,耳边经常听到的是快.快点.再快点!我真想说快你妹!但是,我不得不承认的是:我只有两只手... 后来,在群里看到有人分享了一个连接大 ...
- Spark源码剖析(九):TaskScheduler原理与源码剖析
接着上期内核源码(六)的最后,DAGSchedule会将每个Job划分一系列stage,然后为每个stage创建一批task(数量与partition数量相同),并计算其运行的最佳位置,最后针对这一批 ...
- TensorBoard的使用(结合线性模型)
TensorBoard是TensorFlow 的可视化工具.主要为了更方便用户理解 TensorFlow 程序.调试与优化,用户可以用 TensorBoard 来展现 TensorFlow 图像,绘制 ...
- 代码审计之XiaoCms(后台任意文件上传至getshell,任意目录删除,会话固定漏洞)
0x00 前言 这段时间就一直在搞代码审计了.针对自己的审计方法做一下总结,记录一下步骤. 审计没他,基础要牢,思路要清晰,姿势要多且正. 下面是自己审计的步骤,正在逐步调整,寻求效率最高. 0x01 ...