Description
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.
Sample Input
2 2 0 0 2
90.0000000000
3 2 0 0 2 -2 2
135.0000000000
4 2 0 0 2 -2 0 0 -2
270.0000000000
2 2 1 1 2
36.8698976458
Hint
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:
在C語言的math.h或C++中的cmath中有兩個求反正切的函數atan(double x)與atan2(double y,double x) 他們返回的值是弧度 要轉化爲角度再自己處理下。
前者接受的是一個正切值(直線的斜率)得到夾角,但是由於正切的規律性本可以有兩個角度的但它卻只返回一個,因爲atan的值域是從-90~90 也就是它只處理一四象限,所以一般不用它。
第二個atan2(double y,double x) 其中y代表已知點的Y座標 同理x ,返回值是此點與遠點連線與x軸正方向的夾角,這樣它就可以處理四個象限的任意情況了,它的值域相應的也就是-180~180了
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
double a[100010];
int n;
int main()
{
while(~scanf("%d",&n))
{
double x,y;
for(int i=0;i<n;i++)
{
scanf("%lf%lf",&x,&y);
a[i]=atan2(y,x);
}
sort(a,a+n);
a[n]=a[0]+2*acos(-1.0);
double ans=2*acos(-1.0);
for(int i=0;i<n;i++)
ans=min(ans,2*acos(-1.0)-fabs(a[i+1]-a[i]));
printf("%lf\n",ans*180/acos(-1.0));
}
}