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-Servlet知识总结
目录 Servlet概述 为什么要学习Servlet 什么是 Servlet 工作流程 生命周期 处理请求的方法 HttpServletRequest 和 HttpServletResponse Ht ...
- 【高并发】ReadWriteLock怎么和缓存扯上关系了?!
写在前面 在实际工作中,有一种非常普遍的并发场景:那就是读多写少的场景.在这种场景下,为了优化程序的性能,我们经常使用缓存来提高应用的访问性能.因为缓存非常适合使用在读多写少的场景中.而在并发场景中, ...
- 转 16 jmeter中的监听器以及测试结果分析
16 jmeter中的监听器以及测试结果分析 常用监听器 断言结果.查看结果树.聚合报告.Summary Report.用表格查看结果.图形结果.aggregate graph等 指标分析 -Sa ...
- 。SLI,Service Level Indicator,服务等级指标,其实就是我们选择哪些指标来衡量我们的稳定性。而 SLO,Service Level Objective,服务等级目标,指的就是我们设定的稳定性目标,比如“几个 9”这样的目标。
.SLI,Service Level Indicator,服务等级指标,其实就是我们选择哪些指标来衡量我们的稳定性.而 SLO,Service Level Objective,服务等级目标,指的就是我 ...
- Java——I/O相关练习代码
File文件的相关练习 文件操作的三种方式 文件的相关方法练习 文件创建删除操作 文件练习 FileReader读取文件 读取文件逐行读取 InputStreamReader字符输出流 换行输出 Bu ...
- Spring Cloud与Docker——微服务架构概述
Spring Cloud与Docker--微服务架构概述 单体应用架构概述 微服务概述 微服务的特性 微服务架构的优点 微服务面临的挑战 微服务的设计原则 单体应用架构概述 传统的服务发布都是采用单体 ...
- KVM(虚拟机的迁移)
- MB与Mb
MB/s的含义是兆字节每秒,Mbit/s的含义是兆比特每秒,前者是指每秒传输的字节数量,后者是指每秒传输的比特位数.即B=Byte,b=bit,1Byte=8bit.下载时用的是B,交换机上用的是b, ...
- php之魔术方法 __set(),__get(),__isset(),__unset()
__set()与__get() 当一个类里面,属性被设置为私有属性时,这个属性是不能在外部被访问的.那么当我们又想在外部访问时该怎么办呢,我们可以用方法来实现.举例如下: 1 class Test 2 ...
- Deep Learning论文翻译(Nature Deep Review)
原论文出处:https://www.nature.com/articles/nature14539 by Yann LeCun, Yoshua Bengio & Geoffrey Hinton ...