您的位置:首页 > 其它

【CodeForces】257C - View Angle(计算几何)

2016-10-22 16:20 337 查看
题目链接:点击打开题目

C. View Angle

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and
with all mannequins standing inside or on the boarder of this angle.

As you spend lots of time "glued to the screen", your vision is impaired. So you have to write a program that will pass the check for you.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) —
the number of mannequins.

Next n lines contain two space-separated integers each: xi, yi (|xi|, |yi| ≤ 1000) —
the coordinates of the i-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that
no two mannequins are located in the same point on the plane.

Output

Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10 - 6.

Examples

input
2
2 0
0 2


output
90.0000000000


input
3
2 0
0 2
-2 2


output
135.0000000000


input
4
2 0
0 2
-2 0
0 -2


output
270.0000000000


input
2
2 1
1 2


output
36.8698976458


Note

Solution for the first sample test is shown below:



Solution for the second sample test is shown below:



Solution for the third sample test is shown below:



Solution for the fourth sample test is shown below:



有个坑,刚开始wa了很多次。把每个点与x轴正方向的夹角算出来后,排一下顺序后把每一个点都遍历一遍,以之为起点算角度更新ans就行了。

代码如下:

#include <cstdio>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
#define CLR(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define LL long long
#define MAX 100000
#define PI acos(-1.0)
struct node
{
double x,y,angle;
}a[MAX+11];
double trans(double m) //转化为角度制
{
return 180 * m / PI;
}
double cal(double x,double y)
{
if (x > 0 && y > 0)
return trans(atan(y/x));
else if (x < 0 && y > 0)
return 180 - trans(atan(-y/x));
else if (x < 0 && y < 0)
return 180 + trans(atan(y/x));
else if (x > 0 && y < 0)
return 360 - trans(atan(-y/x));
else if (x == 0 && y > 0)
return 90;
else if (x == 0 && y < 0)
return 270;
else if (x >= 0 && y == 0)
return 0;
else if (x < 0 && y == 0)
return 180;
}
bool cmp(node a,node b)
{
return a.angle < b.angle;
}
int main()
{
int n;
while (~scanf ("%d",&n))
{
for (int i = 1 ; i <= n ; i++)
{
scanf ("%lf %lf",&a[i].x,&a[i].y);
a[i].angle = cal(a[i].x , a[i].y);
}
sort(a+1,a+n+1,cmp);
double ans = a
.angle - a[1].angle;
for (int i = 2 ; i <= n ; i++)
{
double t = a[i-1].angle - a[i].angle;
ans = min(ans , t <= 0 ? t + 360 : t);
}
printf ("%lf\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: