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 ...
随机推荐
- 机器学习7-模型保存&无监督学习
模型保存和加载 sklearn模型的保存和加载API from sklearn.externals import joblib 保存:joblib.dump(rf, 'test.pkl') 加载:es ...
- PW6513高压40V的LDO芯片,SOT89封装
一般说明 PW6513系列是一款高精度,高输入电压,低静态电流,高速,低具有高纹波抑制的线性稳压器.输入电压高达40V,负载电流为在电压=5V和VIN=7V时高达300mA.该设备采用BCD工艺制造. ...
- 【工具篇】Mysql的安装和使用
[导读]Mysql是数据分析师入门级的技能之一,对于很多小白同学来说,可能还没有机会接触SQL知识.那么我们如何熟悉和练习SQL呢,今天教大家安装两个软件:MySQL和Navicat.后续我们会推出S ...
- Mac中安装Git
Mac 安装git 打开Mac终端输入git命令 如果出现以下代码说明已经安装 usage: git [--version] [--help] [-C <path>] [-c <na ...
- Java语法糖详解
语法糖 语法糖(Syntactic Sugar),也称糖衣语法,是由英国计算机学家 Peter.J.Landin 发明的一个术语,指在计算机语言中添加的某种语法,这种语法对语言的功能并没有影响,但是更 ...
- java画海报二维码
package cn.com.yitong.ares.qrcode; import java.awt.BasicStroke;import java.awt.Color;import java.awt ...
- Win10家庭版Hyper-V出坑(完美卸载,冲突解决以及Device Guard问题)
本文链接:https://blog.csdn.net/hotcoffie/article/details/85043894 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附 ...
- MSSQL 注入笔记
前置知识: 登录名:登录sql server服务器的用户,而不是操作"数据库用户名". 固定服务器角色:就是上面登录名所属的权限组.其中重要的就是"sysadmin&qu ...
- 一文打尽端口复用 VS Haproxy端口复用
出品|MS08067实验室(www.ms08067.com) 本文作者:Spark(Ms08067内网安全小组成员) 1.概述 Haproxy是一个使用c语言开发的高性能负载均衡代理软件,提供tc ...
- XCTF-你是谁
前期工作 查壳,无.运行 不知道有啥用,迷宫题? 逆向分析 文件结构 查看了一下主要逻辑在background中,因为MainActivity的setContentView是background.ba ...