题目:http://codeforces.com/contest/257/problem/C
极角序。使用atan2(y,x)排序。
这题很容易做错的一点就是开始会想到直接用sort升序排序后,最大减去最小即是所求,其实这是不对的。比如给三点:(-1,-1),(-1,1),(-1,2)测一下。
每个黄色区域的两边上的两点肯定是相邻的,我们可以根据这个已知项来解答:
本题我觉得还是很有思维性的。
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
struct Point
{
double x;
double y;
double angle;
};
Point p[100003];
bool cmp(Point a,Point b)
{
return a.angle<b.angle;
}
int main()
{
int n;
scanf(" %d",&n);
for(int i=0; i<n; i++)
{
scanf(" %lf %lf",&p[i].x,&p[i].y);
p[i].angle = atan2(p[i].y,p[i].x);
}
sort(p,p+n,cmp);
p[n].angle = p[0].angle + 2 * acos(-1.0);
double ans = 2*acos(-1.0);
for(int i=0; i<n; i++)
{
ans = min(ans,2 * acos(-1.0) - fabs(p[i+1].angle - p[i].angle));
}
printf("%lf\n",ans*180.0/acos(-1.0));
return 0;
}