zoukankan      html  css  js  c++  java
  • 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
    ",minn / Pi * 180);
        return 0;
    }
  • 相关阅读:
    hdu 3268 09 宁波 现场 I
    hdu 3697 10 福州 现场 H
    CodeForces Round #521 (Div.3) D. Cutting Out
    #Leetcode# 226. Invert Binary Tree
    zufe 蓝桥选拔
    #Leetcode# 100. Same Tree
    #Leetcode# 6. ZigZag Conversion
    PAT 1084 外观数列
    #Leetcode# 38. Count and Say
    #Leetcode# 22. Generate Parentheses
  • 原文地址:https://www.cnblogs.com/tiberius/p/8488553.html
Copyright © 2011-2022 走看看