HDU-6242:Geometry Problem(随机化+几何)
来源:互联网 发布:linux 查看数据包 编辑:程序博客网 时间:2024/06/06 15:00
Geometry Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1587 Accepted Submission(s): 288
Special Judge
Problem Description
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 givenN 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 .
You are given
Input
The first line is the number of test cases.
For each test case, the first line contains one positive numberN(1≤N≤105) .
The followingN 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 N points are distinct.
For each test case, the first line contains one positive number
The following
Output
For each test case, output a single line with three real numbers XP,YP,R , where (XP,YP) is the coordinate of required point P . Three real numbers you output should satisfy 0≤|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 asR if it is within an absolute error of 10−3 of R .
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
Sample Input
171 11 01 -10 1-1 10 -1-1 0
Sample Output
0 0 1
思路:从n个点中随机3个点求出其共圆的圆心,判断其是否满足条件。
#include<bits/stdc++.h>using namespace std;const int MAX=2e5;struct Point{ double x,y;}p[MAX];double dis(Point a,Point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}Point solve(Point a,Point b,Point c)//三点共圆圆心公式{ double x=( (a.x*a.x-b.x*b.x+a.y*a.y-b.y*b.y)*(a.y-c.y)-(a.x*a.x-c.x*c.x+a.y*a.y-c.y*c.y)*(a.y-b.y) ) / (2*(a.y-c.y)*(a.x-b.x)-2*(a.y-b.y)*(a.x-c.x)); double y=( (a.x*a.x-b.x*b.x+a.y*a.y-b.y*b.y)*(a.x-c.x)-(a.x*a.x-c.x*c.x+a.y*a.y-c.y*c.y)*(a.x-b.x) ) / (2*(a.y-b.y)*(a.x-c.x)-2*(a.y-c.y)*(a.x-b.x)); return (Point){x,y};}int main(){ int T,n;cin>>T; while(T--) { scanf("%d",&n); for(int i=0;i<n;i++)scanf("%lf%lf",&p[i].x,&p[i].y); if(n==1||n==2){printf("%lf %lf %lf\n",p[0].x+1,p[0].y,1.0);continue;} if(n==3||n==4){printf("%lf %lf %lf\n",(p[1].x+p[2].x)/2,(p[1].y+p[2].y)/2,dis(p[1],p[2])/2);continue;} while(1) { int a=rand()%n; int b=rand()%n; int c=rand()%n; if(a==b||a==c||b==c)continue; if(fabs((p[b].y-p[a].y)*(p[c].x-p[b].x)-(p[c].y-p[b].y)*(p[b].x-p[a].x))<=1e-6)continue; Point q=solve(p[a],p[b],p[c]); int sum=0; for(int i=0;i<n;i++) { if(abs(dis(p[i],q)-dis(p[a],q))<=1e-6)sum++; } if(2*sum>=n){printf("%lf %lf %lf\n",q.x,q.y,dis(p[a],q));break;} } } return 0;}
阅读全文
1 0
- HDU-6242:Geometry Problem(随机化+几何)
- HDU 6242/2017CCPC哈尔滨 Geometry Problem 【随机化+计算几何】
- HDU 6242 Geometry Problem(2017 CCPC 哈理工)(随机化+计算几何)
- hdu 6242 Geometry Problem(随机化+三点求外接圆)
- HDU 6242 Geometry Problem (随机数,几何)
- 2017 CCPC 哈尔滨 M ( hdu 6242) Geometry Problem (随机化 + 三角形外心)
- hdu 1086 You can Solve a Geometry Problem too(计算几何水题)
- hdu 1086 You can Solve a Geometry Problem too(几何(线段相交))
- HDU 1086 You can Solve a Geometry Problem too(计算几何)
- HDU 1086 You can Solve a Geometry Problem too (计算几何 判断线段相交)
- hdu 5298 Solid Geometry Homework(几何)
- Geometry Problem HDU
- HDU 1086 You can Solve a Geometry Problem too && 简单几何
- HDU 1086 You can Solve a Geometry Problem too [计算几何]
- 几何水题 acdream 1414 Geometry Problem
- You can Solve a Geometry Problem too(计算几何_求线段相交)
- HDUOJ-1086 You can Solve a Geometry Problem too(简单几何)
- You can Solve a Geometry Problem too (hdu1086)几何,判断两线段相交
- 11月21日笔记
- android recycleview 没有填满屏幕
- 机器学习伊始
- redux常用的几个函数
- 栈的应用之括号的匹配
- HDU-6242:Geometry Problem(随机化+几何)
- 机器学习 基础
- 将毫秒转换为时间(HH:ss:mm)
- DAY1之Python复习
- 「蓝光」「720/1080p」「HR-HDTV」等视频制式都是什么意思?清晰度对比如何?
- mysql安装卡在Type and NetWorking,无法继续安装。
- leetcode解题方案--039-- CombinationSum
- 双线性插值
- 火狐浏览器所有历史版本下载地址