hdu 6242 Geometry Problem
Geometry Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1722 Accepted Submission(s): 304
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 N points 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.
7
1 1
1 0
1 -1
0 1
-1 1
0 -1
-1 0
1 #include <iostream>
2 #include <string.h>
3 #include <algorithm>
4 #include <cstdio>
5 #include <cstdlib>
6 #include <cmath>
7 using namespace std;
8 typedef long long ll;
9 const int maxn = 1e5+10;
10 struct nod
11 {
12 double x;
13 double y;
14 }nu[maxn];
15 int vis[maxn];
16 double xx1,yy1,xx2,yy2,xx3,yy3;
17 void getr(double &x,double &y,double &r)
18 {
19 // printf("%lf %lf\n",xx2,xx1);
20 double a=2*(xx2-xx1);
21 double b=2*(yy2-yy1);
22 double c=xx2*xx2-xx1*xx1+yy2*yy2-yy1*yy1;
23 double d=2*(xx3-xx2);
24 double e=2*(yy3-yy2);
25 double f=xx3*xx3-xx2*xx2+yy3*yy3-yy2*yy2;
26 x=(b*f-e*c)/(b*d-e*a);
27 y=(a*f-d*c)/(a*e-b*d);
28 r=sqrt((x-xx1)*(x-xx1)+(y-yy1)*(y-yy1));
29 // printf("%lf %lf %lf\n",x,y,r);
30 }
31 int main()
32 {
33 int t;
34 int n;
35 scanf("%d",&t);
36 while(t--)
37 {
38
39 scanf("%d",&n);
40 for(int i=0;i<n;++i)
41 scanf("%lf%lf",&nu[i].x,&nu[i].y);
42 if(n<=2)
43 {
44 printf("%lf %lf %lf\n",nu[0].x,nu[0].y,0.0);
45 }
46 else if(n<=4)
47 {
48 double x,y,r;
49 x=(nu[0].x+nu[1].x)/2;
50 y=(nu[0].y+nu[1].y)/2;
51 r=sqrt((x-nu[0].x)*(x-nu[0].x)+(y-nu[0].y)*(y-nu[0].y));
52 printf("%lf %lf %lf\n",x,y,r);
53 }
54 else
55 {
56 while (true)
57 {
58 int coo1=rand()%n;
59 int coo2=rand()%n;
60 int coo3=rand()%n;
61 if(coo1==coo2 || coo1==coo3 || coo2==coo3) continue;
62 xx1=nu[coo1].x; yy1=nu[coo1].y;
63 xx2=nu[coo2].x; yy2=nu[coo2].y;
64 xx3=nu[coo3].x; yy3=nu[coo3].y;
65 if(fabs((yy3-yy2)*(xx2-xx1)-(xx3-xx2)*(yy2-yy1))<=1e-6)
66 continue;
67 double x=0,y=0,r=0;
68 getr(x,y,r);
69 int cnt=0;
70 for(int i=0;i<n;++i)
71 {
72 if(fabs(r*r- ((nu[i].x-x)*(nu[i].x-x)+(nu[i].y-y)*(nu[i].y-y)) )<=1e-6)
73 ++cnt;
74 }
75 if(cnt*2>=n)
76 {
77 printf("%lf %lf %lf\n",x,y,r);
78 break;
79 }
80 }
81 }
82 }
83 return 0;
84 }
hdu 6242 Geometry Problem的更多相关文章
- HDU - 6242 Geometry Problem (几何,思维,随机)
Geometry Problem HDU - 6242 Alice is interesting in computation geometry problem recently. She found ...
- HDU 6242 Geometry Problem(计算几何 + 随机化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6242 思路:当 n == 1 时 任取一点 p 作为圆心即可. n >= 2 && ...
- 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 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/ ...
- 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 ...
- 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 ...
随机推荐
- Java运算符概要与数学函数
运算符概要 在Java中,使用算术运算符+,-,*,/表示加减乘除运算,当参与/的运算的两个操作数都是整数时,表示整数除法,否则,表示浮点除法.整数的求余操作(有时称为取模),用%表示,例如,15/2 ...
- 学习Java第一天
public 保证类名和文件名一致 关键字字母全小写,编辑器中有颜色标记 null空常量不能打印 变量就是内存中的存储空间 计算机中最小的存储单元时字节(byte) //1字节(B) = 8位(bit ...
- Vue案例之todoLIst实现
使用Vue实现todolist案例,如有不对敬请大佬多多指教 功能: 1.增加功能:在新增版块里面的输入框内输入数据,点击后面的"添加"按钮,将输入的数据添加到列表中,默认是未完成 ...
- ROS教程(一):ROS安装教程(详细图文)
ros教程:ros安装 目录 前言 一.版本选择 二.开始安装 2.1 软件中心配置 2.2 添加源 2.3 安装 三.验证ROS 前言 关于ROS(Robot OS 机器人操作系统),估计看这个教程 ...
- jmeter-并发及常数吞吐量定时器设定
- Canal介绍以及应用
Canal介绍以及应用 应用场景: canal [kə'næl],译意为水道/管道/沟渠,主要用途是基于 MySQL 数据库增量日志解析,提供增量数据订阅和消费 早期阿里巴巴因为杭州和美国双机房部署, ...
- Spark底层原理详细解析(深度好文,建议收藏)
Spark简介 Apache Spark是用于大规模数据处理的统一分析引擎,基于内存计算,提高了在大数据环境下数据处理的实时性,同时保证了高容错性和高可伸缩性,允许用户将Spark部署在大量硬件之上, ...
- SpringBoot配置文件基础部分说明
SpringBoot-yml文件配置说明 友情提示:有一些代码中有乱码,请脑补删除,适合快速入门 #开启spring的Bebug模式,可以查看有哪些自动配置生效 #debug=true #开启热启动, ...
- Dubbo 最基本的几个需求
需求 http://dubbo.apache.org/zh-cn/docs/user/preface/requirements.html 在大规模服务化之前,应用可能只是通过 RMI 或 Hessia ...
- springmvc框架java.lang.NoSuchMethodException问题解决
例子:https://blog.csdn.net/huaidandaidai1/article/details/81979704 原因: 在java中,如果一个类A没有自己写构造方法,那么java会自 ...