首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【CodeForces】257C - View Angle(计算几何)

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

作者头像
FishWang
发布2025-08-26 14:37:40
发布2025-08-26 14:37:40
6300
代码可运行
举报
运行总次数:0
代码可运行

题目链接:点击打开题目

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

代码语言:javascript
代码运行次数:0
运行
复制
2
2 0
0 2

output

代码语言:javascript
代码运行次数:0
运行
复制
90.0000000000

input

代码语言:javascript
代码运行次数:0
运行
复制
3
2 0
0 2
-2 2

output

代码语言:javascript
代码运行次数:0
运行
复制
135.0000000000

input

代码语言:javascript
代码运行次数:0
运行
复制
4
2 0
0 2
-2 0
0 -2

output

代码语言:javascript
代码运行次数:0
运行
复制
270.0000000000

input

代码语言:javascript
代码运行次数:0
运行
复制
2
2 1
1 2

output

代码语言:javascript
代码运行次数:0
运行
复制
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就行了。

代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#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;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档