您的位置:首页 > 其它

codeforces 257 C. View Angle (数学)

2016-10-23 17:51 239 查看
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:



包含所给所有点的最小的角度,利用反函数atan( )求与x正半轴夹角,360-相邻两边的最大角 就是解
代码:
一)
/*注意角度化成度数形式*/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define PI acos(-1.0)
using namespace std;

int main()
{
int n;
double x,y;
double angle[100010];
scanf("%d",&n);
int i;
for(i=0;i<n;i++)
{
scanf("%lf%lf",&x,&y);
if(y==0)
{
if(x>0) angle[i]=0;
else angle[i]=180;
}
else if(x==0)
{
if(y>0) angle[i]=90;
else angle[i]=270;
}
else if(x>0&&y>0)
angle[i]=atan(y/x)*(180/PI);
else if(x<0&&y>0)
angle[i]=90+atan(-1*x/y)*(180/PI);
else if(x<0&&y<0)
angle[i]=180+atan(y/x)*(180/PI);
else
angle[i]=270+atan(-1*x/y)*(180/PI);
}
double maxn=0.0,minn;
sort(angle,angle+n);
for(i=0;i<n-1;i++)
{
maxn=max(maxn,angle[i+1]-angle[i]);
}
maxn=max(maxn,360-angle[n-1]+angle[0]);
minn=360-maxn;
printf("%.8lf\n",minn);
return 0;
}


二)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define PI acos(-1.0)
using namespace std;
struct Node
{
double x,y;
double angle;
}node[100000+10];
bool cmp(Node a,Node b)
{
return a.angle<b.angle;
}
double Angle(double x,double y)
{
if(y==0)
{
if(x>0) return 0;
else return 180;
}
else if(x==0)
{
if(y>0) return 90;
else return 270;
}
else if(x>0&&y>0)
return atan(y/x)*(180/PI);
else if(x<0&&y>0)
return 90+atan(-x/y)*(180/PI);
else if(x<0&&y<0)
return 180+atan(y/x)*(180/PI);
else
return 270+atan(-x/y)*(180/PI);
}
int main()
{
int n;
//double x,y;
//double angle[1010];
scanf("%d",&n);
int i;
for(i=0;i<n;i++)
{
scanf("%lf %lf",&node[i].x,&node[i].y);
node[i].angle=Angle(node[i].x,node[i].y);
}
double maxn=0.0,minn;
sort(node,node+n,cmp);
for(i=0;i<n-1;i++)
{
maxn=max(maxn,node[i+1].angle-node[i].angle);
}
maxn=max(maxn,360-node[n-1].angle+node[0].angle);
minn=360-maxn;
printf("%.8lf\n",minn);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: