• codeforces 257 C


    codeforces 257 C

    C. View Angle

    introduction

    找一个最小角,使得所有的点都落在这个角的内部,包括角的边

    method

    可以将这个问题转换成,找一个最大角,使得所有的点都不落到这个角的内部。这样的角就是相邻两个点组成的角。可以枚举这样的角,找到一个最大的,然后关于360°取补。

    tips

    • pi可以用acos(-1)来表示
    • 角的范围应该是在区间[0 , 2*pi],根据余弦值求反函数需要处理对称的情况

    code

    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<cmath>
    #include<map>
    #include<istream>
    #define DEBUG(x) cout<<#x<<" = "<<x<<endl
    #define pi acos(-1)
    using namespace std;
    struct angle{
        double deg;
        angle(){}
        angle(double d)
        {
            deg=d;
        }
        bool operator<(const angle &a)const
        {
            return deg<a.deg;
        }
    };
    int main()
    {
    //    freopen("in.txt","r",stdin);
        int n;
        scanf("%d",&n);
        vector<angle>ags;
        for(int i=0;i<n ;i++ ){
            double x,y,d;
            scanf("%lf%lf",&x,&y);
            d=acos(x/sqrt(x*x+y*y));
            if(y<0)d=2*pi-d;
            ags.push_back(angle(d));
        }
        sort(ags.begin(),ags.end());
        double maxag=0;
        for(int i=1;i<n ;i++ ){
            maxag=max(maxag,ags[i].deg-ags[i-1].deg);
        }
        ///找出一个最大的空角
        maxag=max(maxag,ags[0].deg+2*pi-ags[n-1].deg);
        maxag=(2*pi-maxag)/(pi)*180;
        printf("%.10f",maxag);
    }
    
    
  • 相关阅读:
    风雨中,苦算什么!!!
    痛心疾首+无奈绝望!!!
    PHP页面跳转总结
    Java的HttpClient的实现
    java细节篇(==和equals的区别)
    cmd命令笔记
    Python的HttpClient实现
    常用linux命令
    Go的HttpClient实现
    android问题笔记集
  • 原文地址:https://www.cnblogs.com/MalcolmMeng/p/10181773.html
Copyright © 2020-2023  润新知