2017 CCPC 哈尔滨站 HDU 6242

Geometry Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1091    Accepted Submission(s): 208
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 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.

Input

The first line is the number of test cases.

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 Npoints are distinct.

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 as R if it is within an absolute error of 10?3 of R.

Sample Input

1

7

1 1

1 0

1 -1

0 1

-1 1

0 -1

-1 0

Sample Output

0 0 1

题意  给出n个点 确定一个圆的圆心和半径  使得至少n/2个点(向上取整)在该圆上 对于每组样例至少有一个解

解析 我们知道  在n个点中每个点在圆上的概率都为0.5  三个不共线的点确定一个外接圆  我们随机取三个点 这三个点的外接圆满足条件的概率为0.5*0.5*0.5=0.125

每次随机消耗的时间复杂度为1e5  枚举1秒内可以100 次   基本可以得到答案

AC代码

 1 #include <cstdio>
 2 #include <cmath>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <iostream>
 6 #include <sstream>
 7 #include <algorithm>
 8 #include <string>
 9 #include <queue>
10 #include <vector>
11 using namespace std;
12 const int maxn= 1e5+10;
13 const double eps= 1e-6;
14 const int inf = 0x3f3f3f3f;
15 typedef long long ll;
16 struct point
17 {
18     double x,y;
19 }a[maxn];
20 int n;
21 double dis(point a,point b)   //两点间距离
22 {
23     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
24 }
25 bool waijie(point p1,point p2,point p3,point &ans)   //引用修改圆心的值
26 {
27     if(fabs((p3.y-p2.y)*(p2.x-p1.x)-(p2.y-p1.y)*(p3.x-p2.x))<=eps)return false;  //三点共线 没有外接圆
28     double Bx = p2.x - p1.x, By = p2.y - p1.y;            //外接圆板子
29     double Cx = p3.x - p1.x, Cy = p3.y - p1.y;
30     double D = 2 * (Bx * Cy - By * Cx);
31     double cx = (Cy * (Bx * Bx + By * By) - By * (Cx * Cx + Cy * Cy)) / D + p1.x;
32     double cy = (Bx * (Cx * Cx + Cy * Cy) - Cx * (Bx * Bx + By * By)) / D + p1.y;
33     ans.x=cx,ans.y=cy;
34     return true;
35 }
36 bool check(point mid,double d)     //检查是否有n/2个点在外接圆上
37 {
38     int ans=0;
39     for(int i=1;i<=n;i++)
40     {
41         if(fabs(dis(a[i],mid)-d)<=eps)
42             ans++;
43         if((ans+(n-i))*2<n)       //简单优化一下 如果还未判断的点的数量加上已经满足条件的点的数量小于n/2 false
44             return false;
45     }
46     if(ans*2>=n)
47         return true;
48     return false;
49 }
50 int main()
51 {
52     int t;
53     scanf("%d",&t);
54     while(t--)
55     {
56         scanf("%d",&n);
57         for(int i=1;i<=n;i++)
58             scanf("%lf%lf",&a[i].x,&a[i].y);
59         if(n<=2)                                   //n小于等于4特判
60         {
61             printf("%lf %lf %lf\n",a[1].x,a[1].y,0.0);
62             continue;
63         }
64         else if(n<=4)
65         {
66             printf("%lf %lf %lf\n",(a[1].x+a[2].x)/2,(a[1].y+a[2].y)/2,dis(a[1],a[2])/2);
67             continue;
68         }
69         while(true)
70         {
71             point aa=a[rand()%n+1],bb=a[rand()%n+1],cc=a[rand()%n+1];   //随机产生3个点
72             point xin;
73             if(!waijie(aa,bb,cc,xin))
74                 continue;
75             double r=dis(aa,xin);
76             if(check(xin,r))
77             {
78 //                printf("%lf %lf\n",aa.x,aa.y);
79 //                printf("%lf %lf\n",bb.x,bb.y);
80 //                printf("%lf %lf\n",cc.x,cc.y);
81                 printf("%lf %lf %lf\n",xin.x,xin.y,r);
82                 break;
83             }
84         }
85     }
86     return 0;
87 }
时间: 2024-11-12 07:53:42

2017 CCPC 哈尔滨站 HDU 6242的相关文章

HDU 6240 Server(2017 CCPC哈尔滨站 K题,01分数规划 + 树状数组优化DP)

题目链接  2017 CCPC Harbin Problem K 题意  给定若干物品,每个物品可以覆盖一个区间.现在要覆盖区间$[1, t]$. 求选出来的物品的$\frac{∑a_{i}}{∑b_{i}}$的最小值. 首先二分答案,那么每个物品的权值就变成了$x * b_{i} - a_{i}$ 在判断的时候先把那些权值为正的物品全部选出来, 然后记录一下从$1$开始可以覆盖到的最右端点的位置. 接下来开始DP,按照区间的端点升序排序(左端点第一关键字,右端点第二关键字) 问题转化为能否用剩

HDU 6271 Master of Connected Component(2017 CCPC 杭州 H题,树分块 + 并查集的撤销)

题目链接  2017 CCPC Hangzhou Problem H 思路:对树进行分块.把第一棵树分成$\sqrt{n}$块,第二棵树也分成$\sqrt{n}$块.    分块的时候满足每个块是一个连通块,那么每个块就有一个共同的祖先. 把询问按照第一个点被第一棵树的哪个祖先管辖和第二个点被第二棵树的哪个祖先管辖,分成$n$类. 每一类询问一起处理,处理完后用可撤销并查集恢复到之前的状态. 每一类询问之间依次转移,每次转移,移动次数不会超过$\sqrt{n}$次. 最后总时间复杂度$O(n^{

2017 CCPC Final小结 By JSB @ Reconquista

Statistics TYPE: Onsite Contest NAME: 2017 - CCPC - Final PLAT: pc^2 TIME: 2017/12/03 09:00-14:00 LOCA: Harbin Institute of Technology TEAM: Reconquista [shb,lsmll,jsb] RANK: 3/117 2.56% (*Including Unofficial Teams) SOLVE: 9/11 PENALTY: 884 ? A - 11

2017 CCPC 杭州赛区小结 By JSB @ Reconquista

Statistics TYPE: Onsite Contest NAME: 2017 - CCPC - Hangzhou PLAT: pc^2 TIME: 2017/11/05 09:00-14:00 LOCA: Zhejiang SCI-TECH University Xiasha Campus TEAM: Reconquista[shb,lsmll,jsb] RANK: 10/190 5.26% (*Including Unofficial Teams) SOLVE: 7/12 PENALT

2018 CCPC 吉林站 H Lovers

2018 CCPC 吉林站 H Lovers 传送门:https://www.spoj.com/problems/LIS2/en/ 题意: q次操作 1.将第l~r个数的左边和和右边都加上一个数d, 使得这个数变成 \(ds_id\)的形式 2.询问区间和 题解: 线段树题 这个update操作不好维护,我们来冷静分析一下 对于一个数x,他的长度为len,我们在他后面加上一个数d,那么他的长度就变成了len+1,这个数x就变成了\(x*10+d\) 同理,在前面加上一个数,这个数x就变成了\(d

Permutation-水题-2017中国大学生程序设计竞赛-哈尔滨站-重现赛

Permutation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0Special Judge Problem Description A permutation p1,p2,...,pn of 1,2,...,n is called a lucky permutatio

A Simple Stone Game-找素因子(欧拉函数)-2017中国大学生程序设计竞赛-哈尔滨站-重现赛

A Simple Stone Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description After he has learned how to play Nim game, Bob begins to try another ston

hdu 6152 : Friend-Graph (2017 CCPC网络赛 1003)

题目链接 裸的结论题.百度 Ramsey定理.刚学过之后以为在哪也不会用到23333333333,没想到今天网络赛居然出了.顺利在题面更改前A掉~~~(我觉得要不是我开机慢+编译慢+中间暂时死机,我还能再早几分钟过掉它 #include<bits/stdc++.h> using namespace std; int g[8][8]; int n; void solve() { for(int i=1; i<=n; i++) for(int j=i+1; j<=n; j++) for

2017中国大学生程序设计竞赛-哈尔滨站 H - A Simple Stone Game

A Simple Stone Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1526    Accepted Submission(s): 346 Problem Description After he has learned how to play Nim game, Bob begins to try another