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

本文介绍了一个算法问题,即计算平面内多个假人站立时所需的最小视角角度,确保所有假人都位于该角度范围内。通过计算每个假人相对于坐标原点的角度,并进行排序来找到最小覆盖角度。

题目链接:点击打开题目

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[n].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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值