View Angle CodeForces - 257C

原题链接
考察:思维+计算几何
思路:
  预处理所有点的度数,存在一个最小角的包含所有的点,那么必然存在最大的相邻点之间的角度没有包含所有的点.
  反三角函数的返回值是弧度,详情看此篇GO

Code

#include <iostream> 
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 100010;
const double PI = acos(-1);
struct Point{
	int x,y;
	double ang;
	bool operator<(const Point& p){
		return this->ang<p.ang;
	}
}point[N];
int n;
double cal(int x,int y)
{
	if(!x) return y>0?90:270;
	if(!y) return x>0?0:180;
	if(x>0&&y>0) return atan(y*1.0/x)*180/PI;
	else if(x>0) return 270+atan(x*1.0/abs(y))*180/PI;
	else if(y>0) return 90+atan(abs(x)*1.0/y)*180/PI;
	else return 180+atan(y*1.0/x)*180/PI;
}
int main()
{
	scanf("%d",&n);
	double ans = 0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&point[i].x,&point[i].y);
		point[i].ang = cal(point[i].x,point[i].y);
	}
	sort(point+1,point+n+1);
	for(int i=1;i<=n;i++)
		if(i>1) ans = max(point[i].ang-point[i-1].ang,ans);
	ans = max(point[1].ang-point[n].ang+360,ans);
	printf("%.10lf\n",360-ans);
	return 0;
}
posted @ 2021-07-29 10:06  acmloser  阅读(26)  评论(0编辑  收藏  举报