Alice is interesting in computation geometry problem recently. She found a interesting problem and solved it easily. Now she will give this problem to you :

You are given NN distinct points (Xi,Yi)(Xi,Yi) on the two-dimensional plane. Your task is to find a point PP and a real number RR, such that for at least ⌈N2⌉⌈N2⌉ given points, their distance to point PP is equal to RR. 

InputThe first line is the number of test cases.

For each test case, the first line contains one positive number N(1≤N≤105)N(1≤N≤105).

The following NN lines describe the points. Each line contains two real numbers XiXiand YiYi (0≤|Xi|,|Yi|≤103)(0≤|Xi|,|Yi|≤103) indicating one give point. It's guaranteed that NN points are distinct. 
OutputFor each test case, output a single line with three real numbers XP,YP,RXP,YP,R, where (XP,YP)(XP,YP) is the coordinate of required point PP. Three real numbers you output should satisfy 0≤|XP|,|YP|,R≤1090≤|XP|,|YP|,R≤109.

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 RR if it is within an absolute error of 10−310−3 of RR. 
Sample Input

1
7
1 1
1 0
1 -1
0 1
-1 1
0 -1
-1 0

Sample Output

0 0 1

题意:给定N个点,求一个圆,使得圆上的点大于大于一半,保证有解。

思路:既然保证有解,我们就随机得到三角形,然后求外接圆取验证即可。

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const double eps=1e-;
const double pi=acos(-1.0);
struct point{
double x,y;
point(double a=,double b=):x(a),y(b){}
};
int dcmp(double x){ return fabs(x)<eps?:(x<?-:);}
point operator +(point A,point B) { return point(A.x+B.x,A.y+B.y);}
point operator -(point A,point B) { return point(A.x-B.x,A.y-B.y);}
point operator *(point A,double p){ return point(A.x*p,A.y*p);}
point operator /(point A,double p){ return point(A.x/p,A.y/p);}
point rotate(point A,double rad){
return point(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
}
bool operator ==(const point& a,const point& b) {
return dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==;
}
double dot(point A,point B){ return A.x*B.x+A.y*B.y;}
double det(point A,point B){ return A.x*B.y-A.y*B.x;}
double dot(point O,point A,point B){ return dot(A-O,B-O);}
double det(point O,point A,point B){ return det(A-O,B-O);}
double length(point A){ return sqrt(dot(A,A));}
double angle(point A,point B){ return acos(dot(A,B)/length(A)/length(B));}
point jiaopoint(point p,point v,point q,point w)
{ //p+tv q+tw,点加向量表示直线,求直线交点
point u=p-q;
double t=det(w,u)/det(v,w);
return p+v*t;
}
point GetCirPoint(point a,point b,point c)
{
point p=(a+b)/; //ab中点
point q=(a+c)/; //ac中点
point v=rotate(b-a,pi/2.0),w=rotate(c-a,pi/2.0); //中垂线的方向向量
if (dcmp(length(det(v,w)))==) //平行
{
if(dcmp(length(a-b)+length(b-c)-length(a-c))==) return (a+c)/;
if(dcmp(length(b-a)+length(a-c)-length(b-c))==) return (b+c)/;
if(dcmp(length(a-c)+length(c-b)-length(a-b))==) return (a+b)/;
}
return jiaopoint(p,v,q,w);
}
const int maxn=;
point a[maxn]; int F[maxn];
bool check(point S,double R,int N){
int num=;
rep(i,,N){
if(dcmp(length(a[i]-S)-R)==) num++;
}
if(num>=(N+)/) return true; return false;
}
int main()
{
int T,N,M;
scanf("%d",&T);
while(T--){
scanf("%d",&N);
rep(i,,N) scanf("%lf%lf",&a[i].x,&a[i].y);
if(N==) printf("%.6lf %.6lf %.6lf\n",a[].x,a[].y,0.0);
else if(N==) printf("%.6lf %.6lf %.6lf\n",(a[].x+a[].x)/,(a[].y+a[].y)/,length(a[]-a[])/);
else {
while(true){
rep(i,,N) F[i]=i;
random_shuffle(F+,F+N+);
point S=GetCirPoint(a[F[]],a[F[]],a[F[]]);
double R=length(S-a[F[]]);
if(check(S,R,N)) {
printf("%.6lf %.6lf %.6lf\n",S.x,S.y,R);
break;
}
}
}
}
return ;
}

HDU - 6242:Geometry Problem(随机+几何)的更多相关文章

  1. HDU - 6242 Geometry Problem (几何,思维,随机)

    Geometry Problem HDU - 6242 Alice is interesting in computation geometry problem recently. She found ...

  2. hdu 6242 Geometry Problem

    Geometry Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Other ...

  3. HDU 6242 Geometry Problem(计算几何 + 随机化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6242 思路:当 n == 1 时 任取一点 p 作为圆心即可. n >= 2 && ...

  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. LA 4676 Geometry Problem (几何)

    ACM-ICPC Live Archive 又是搞了一个晚上啊!!! 总算是得到一个教训,误差总是会有的,不过需要用方法排除误差.想这题才几分钟,敲这题才半个钟,debug就用了一个晚上了!TAT 有 ...

  6. You can Solve a Geometry Problem too (hdu1086)几何,判断两线段相交

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3276 ...

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

  8. (hdu step 7.1.2)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/ ...

  9. HDU 1086:You can Solve a Geometry Problem too

    pid=1086">You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Mem ...

随机推荐

  1. unity,如何手动或者使用代码更换材质

    在unity中,我们可能需要更换怪物的贴图,来达到以下效果 方法1:手动配置 找到自己配置好的扩展名为.mat的文件,在怪物的节点找到带Mesh Render的子元素,将其拖放到如图位置 方法2:代码 ...

  2. ubuntu 16.04安装navicat for mysql

    下载地址:官网https://www.navicat.com/download 1.下载 navicat120_mysql_en_x64.tar.gz 文件  2.下载后移到/opt/下 3.解压ta ...

  3. libvirt-qemu-虚拟机设备热插拔

    cpu热插拔 # virsh setvcpus $domain_name --count 4 --live (--config可写入配置文件永久保存) #前提条件和后续激活参考<libvirt- ...

  4. pt-osc原理

    pt-osc原理 1.检查设置环境 测试db是否可连通,并且验证database是否存在 SET SESSION innodb_lock_wait_timeout=1 //InnoDB事务等待行锁的超 ...

  5. qt打包问题。启动失败:Application failed to start because platform plugin “windows” is missing

    qt打包启动失败:Application failed to start because platform plugin “windows” is missing 通常的原因是因为没有platform ...

  6. 20145235李涛《网络对抗》逆向及Bof基础

    上学期实验楼上做过这个实验 直接修改程序机器指令,改变程序执行流程 首先进行反汇编   我们所要修改的是,程序从foo返回,本来要返回到80484ba,而我们要把80484ba修改为getshell的 ...

  7. Centos 6\7 防火墙入门配置

    Centos 6 -- iptables iptables 用法: iptables (选项) (参数) 选项: -t<表>:指定要操纵的表: -A:向规则链中添加条目: -D:从规则链中 ...

  8. [BZOJ1018]堵塞的交通traffic

    Description 有一天,由于某种穿越现象作用,你来到了传说中的小人国.小人国的布局非常奇特,整个国家的交通系统可以被看成是一个2行C列的矩形网格,网格上的每个点代表一个城市,相邻的城市之间有一 ...

  9. [BZOJ2730]矿场搭建

    Description 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处.于是矿主决定在某些挖煤点设立救援出口,使得无论哪一 ...

  10. AIDL与Binder的区别

    Binder是一个远程对象的基础类,核心部分是远程调用机制,这部分是由IBinder定义的. 它是对IBinder类的实现,其中IBinder类提供了这样一个类的标准的本地化实现方式. 大多数开发者不 ...