SOJ - 11512

11512. Big Circle

Constraints

Time Limit: 2 secs, Memory Limit: 256 MB

Description

On the opening ceremony of World Cup there was a part where many kids from around the world was trying to make a big circle on the field which symbolized tolerance and multicultural friendship.

They succeed in making a perfect circle, but as they didn‘t practice very much, kids weren‘t uniformly distributed on circle. You spotted that very quickly, and you want to know what is the minimum distance between some two kids.

Input

First line of the input contains number N (2<=N<=10^5) representing number of kids. Each of next N lines contains two real numbers rounded on two decimal places – coordinates of the each kid. All coordinates will be in interval [-10^6, 10^6]. It is guaranteed that all points will be on circle.

Output

First and only line of output should contain one real number (rounded on two decimal places) – Euclidian distance between two nearest kids. Euclidian distance between points (x1, y1) and (x2, y2) is sqrt((x1-x2)^2+(y1-y2)^2).

Sample Input

5
1.00 4.00
-0.50 -1.60
4.00 1.00
3.12 3.12
-1.60 -0.50

Sample Output

1.56

Hint

In the sample, Kids at points (−0.50,−1.60) and (−1.60,−0.50) are nearest and distance between them is 1.56.

Problem Source

2014年每周一赛第七场/JBOI 2014

题意:求圆上若干点形成的最短弦长度。

思路:先任选三点确定圆心(两弦中垂线交点),再将整个圆平移,使圆心和坐标原点重合,这样就可以从x轴正半轴开始按逆时针将各个点排序,然后再求相邻两点所形成的弦的长度,取最小的就是所求答案。

 1 // Problem#: 11512
 2 // Submission#: 3027891
 3 // The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
 4 // URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
 5 // All Copyright reserved by Informatic Lab of Sun Yat-sen University
 6 #include<bits/stdc++.h>
 7 using namespace std;
 8 typedef long long ll;
 9 struct P{
10     double x,y;
11 };
12 vector<P>v;
13 int n;
14 double X,Y;
15 inline double d2(P a,P b)
16 {
17     return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
18 }
19 int F(P p)
20 {
21     if(p.y == 0)return p.x > 0 ? 0 : 4;
22     if(p.x == 0)return p.y > 0 ? 2 : 6;
23     if(p.x > 0 && p.y > 0)return 1;
24     if(p.x < 0 && p.y > 0)return 3;
25     if(p.x < 0 && p.y < 0)return 5;
26     if(p.x > 0 && p.y < 0)return 7;
27 }
28 bool cmp(const P& a,const P& b)
29 {
30     int fa = F(a),fb = F(b);
31     if(fa != fb)return fa < fb;
32     else return a.y * b.x < a.x * b.y;
33 }
34 int main()
35 {
36     int i;
37     while(~scanf("%d",&n))
38     {
39         v.clear();
40         for(i=0;i<n;i++)
41         {
42             P p;
43             scanf("%lf%lf",&p.x,&p.y);
44             v.push_back(p);
45         }
46         if(n==2)
47         {
48             printf("%.2f\n",sqrt(d2(v[0],v[1])));
49             continue;
50         }
51         double xm01=(v[0].x+v[1].x)/2.0,ym01=(v[0].y+v[1].y)/2.0;
52         double xm12=(v[1].x+v[2].x)/2.0,ym12=(v[1].y+v[2].y)/2.0;
53         double dym01m12 = ym12 - ym01;
54         double dx01=v[1].x-v[0].x,dy01=v[1].y-v[0].y;
55         double dx12=v[2].x-v[1].x,dy12=v[2].y-v[1].y;
56         X = (dym01m12 * dy12 * dy01 - xm01 * dx01 * dy12 + xm12 * dx12 * dy01) / (dx12 * dy01 - dx01 * dy12);
57         if(dy01)
58         Y = ym01 - (X - xm01) * dx01 / dy01;
59         else//dy12 != 0
60         Y = ym12 - (X - xm12) * dx12 / dy12;
61         for(i=0;i<n;i++)
62         {
63             v[i].x-=X;
64             v[i].y-=Y;
65         }
66         sort(v.begin(),v.end(),cmp);
67         double ans=d2(v[0],v[1]);
68         double d;
69         for(i=1;i<n;i++)ans = min(ans,d=d2(v[i-1],v[i]));
70         ans = min(ans,d2(v[n-1],v[0]));
71         printf("%.2f\n",sqrt(ans));
72     }
73     return 0;
74 }
75 /*
76 3
77 0.71 0.71
78 0.71 -0.71
79 -1.00 0.00
80 */                                 

PS:原题数据貌似不够强,去掉第70行代码也能AC,实际上过不了上面那组数据。

时间: 2024-07-30 21:44:14

SOJ - 11512的相关文章

SOJ 4445 2015四川省赛模拟题

背景:赛场上就是因为没开这道题,而没拿到银,回来A了,感觉代码能力还是很弱,一定要先想好再敲,而且注重代码的函数化,这样无论是观感,还是调试都要好很多,逻辑要清晰,看代码要仔细,提交之前通读代码. 题意:起点在原点的frog,开始向右运动,且碰到障碍物就右转,问转多少次? 思路:关键是图的大小范围是109,无法存下,只有用类似链表的方法来存图.这里用了两个容器,一个以X为基准,一个一Y为基准,这两个容器设置很特殊,是为了满足题中特殊的查询需要:查询前进方向最近障碍物. 我的代码: #includ

soj 1015 Jill&#39;s Tour Paths 解题报告

题目描述: 1015. Jill's Tour Paths Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Every year, Jill takes a bicycle tour between two villages. There are different routes she can take between these villages, but she does have an upper limit

SOJ 1051 Biker&#39;s Trip Odometer

题目大意:多组测试样例,每组测试样例输入3个数,第一个表示车轮的直径(浮点型,单位英寸),第二个表示车轮的转数(整型),第三个表示花费的时间(浮点型,单位秒). 求解车轮的总路程(单位:英里)和平均速度(单位:英里/每小时). 以"Trip #: distance MPH"的格式输出. 当转数输入为零时,结束程序. 解题思路:本题主要考察单位的转化,具体的转化系数在题目中有给出.求车轮周长的π是3.1415927. 先将直径的英寸单位转化为英里单位,将时间的秒单位转化为小时. 代码如下

soj 1034 Forest_求树的深度和宽度

题目链接 题意:给你n个节点,m条边,每条边是有向的,这颗树不能有自环,问这颗树的深度和宽度 思路: 不合法情况 1,入度大于1,即存在两条指向同一顶点的边 2,一条入点和出点都相同的边 3,一条变得入点和出点深度已知,但不符合出点的深度是入点的深度加1 4,点入深度未知但出点深度已知 5,遍历完以后,有顶点未遍历,说明有多个根 树的宽度是指,同一层最多有多少个节点 #include <iostream> #include<cstdio> #include<cstring&g

Soj题目分类

-----------------------------最优化问题------------------------------------- ----------------------常规动态规划  SOJ1162 I-Keyboard  SOJ1685 Chopsticks SOJ1679 Gangsters SOJ2096 Maximum Submatrix  SOJ2111 littleken bg SOJ2142 Cow Exhibition  SOJ2505 The County

SOJ 1151. 魔板

题目大意:和soj 1150题目大意差不多,不过数据规模变大了,n可能大于10. 解题思路:在1150的基础上作修改,修改状态重复判断的方式.以前是:扫描整个队列,查重:现在是:引入set集合,每个元素只记录up和down的值,进行查重. 代码如下: 1 #include <iostream> 2 #include <vector> 3 #include <string> 4 #include <set> 5 using namespace std; 6 7

soj 1033 City Road_经典dp

题目链接 题意:给你一个n*m的图,给你b个矩形(在图中,不能通过),只能向上和右走,问左下角到右上角有多少种走法. 思路:经典的dp,dp[i][j]=max(dp[i-1][j],dp[i][j-1]),但是n*m实在太大,不可能直接开这么大的数组,想一下只需要两行的数据就能求出最优解,所以用滚动数组. dp[k][j]=max(dp[1-k][j],dp[k][j-1]),k代表当前行,1-k代表前一行. #include <iostream> #include<cstdio>

soj 4421 最长回文子序列

题意: 给你一个字符串,求该字符串的最长回文子序列长度. 解法: 以前做过连续最长回文子串的长度就是通过构造奇数偶数长度的来做,而本题是不连续. 注意到回文字符串的特点是从左边向右边看和从右边向左边看是一样的效果,那么就可以把目标字符串s导致后产生一个t,子串中如果t和s相同那么这个子串就是回文子串,那么就转化为这两个子串求LCS(longest common subsequent)的问题了. 我的代码: #include <set> #include <map> #include

分段动态规划(SOJ 1162)

SOJ 1162: I-Keyboard http://acm.scu.edu.cn/soj/problem.action?id=1162 Given a string $S$ with length $L$ in which each character has a frequency $F[i], 0\le i<L$, the target is to partition $S$ into $K$ segments satisfying that the sum of products is