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;
    }
  • 相关阅读:
    以查询功能谈下,三层架构中的工厂模式与其中反射的应用
    结对编程
    第四周周结
    知识思考
    自我介绍
    本周开发工作及内容
    第三周周结
    启航
    如何写出健壮的Java代码
    CentOS x64上Matlab R2015b的镜像安装方法与卸载
  • 原文地址:https://www.cnblogs.com/tiberius/p/8488553.html
Copyright © 2011-2022 走看看