Codeforces 257C

题意略。

做这个题有2个收获:

1.认识了atan2(y,x)这个函数,该函数可以求出原点到点(x,y)组成的向量,与x轴正方向形成的夹角。

2.这个题目的思路是极角排序后,取360 - 后一个点的角度与前一个点的角度的差值中最小值为答案,但是当这些点没有布满360度的方向怎么办呢?

这里我们新添一个点,使这个点的角度是360 + 第一个点的角度,用这个点去减最后一个点,这样强行使它们形成一个环。

#include<bits/stdc++.h>
#define Pi acos(-1.0)
#define maxn 100005
using namespace std;

struct Point{
    double x,y,angle;
};

Point store[maxn];

bool cmp(const Point& p1,const Point& p2){
    return p1.angle < p2.angle;
}

int main(){
    int n;
    scanf("%d",&n);
    for(int i = 0;i < n;++i){
        scanf("%lf%lf",&store[i].x,&store[i].y);
        store[i].angle = atan2(store[i].y,store[i].x);
    }
    sort(store,store + n,cmp);
    store[n].angle = store[0].angle + 2 * Pi;
    double minn = 2 * Pi;
    for(int i = 1;i <= n;++i){
        minn = min(minn,2 * Pi - (store[i].angle - store[i - 1].angle));
    }
    printf("%.7lf\n",minn / Pi * 180);
    return 0;
}

 

posted @ 2018-03-01 15:14  温和的提比略  阅读(106)  评论(0编辑  收藏  举报