版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/leekerian/article/details/82120729
首先想到的用atan2极角排序是错的,这题的思路是枚举白色区域,白色区域就是没有点的地方,就是相邻两个点中间的区域,然后逆向求解,注意最后一个点和第一个点的夹角
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=111111;
const double PI=acos(-1.0);
struct Point
{
double x,y;
double at1;
Point(){}
Point(double _x,double _y)
{
x=_x;
y=_y;
}
};
Point p[maxn];
bool cmp(Point a,Point b)
{
return a.at1<b.at1;
}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
scanf("%lf %lf",&p[i].x,&p[i].y);
p[i].at1=atan2(p[i].y,p[i].x);
}
sort(p,p+n,cmp);
double ans=2*PI;
p[n].at1=p[0].at1+2*PI;
for(int i=0;i<n;i++)
{
double t=2*PI-fabs(p[i].at1-p[i+1].at1);
ans=min(ans,t);
}
printf("%.10lf\n",ans*180/PI);
return 0;
}