zoukankan      html  css  js  c++  java
  • 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);
    }
    
    
  • 相关阅读:
    洛谷 P1767 家族_NOI导刊2010普及(10)
    洛谷 P2919 [USACO08NOV]守护农场Guarding the Farm
    COGS 1619. [HEOI2012]采花
    UVA 11181 Probability|Given
    hdu 3336 Count the string
    洛谷 P2176 [USACO14FEB]路障Roadblock
    洛谷 P2691 逃离
    BZOJ 1040: [ZJOI2008]骑士
    vijos 1320 清点人数
    POJ 3417 Network
  • 原文地址:https://www.cnblogs.com/MalcolmMeng/p/10181773.html
Copyright © 2011-2022 走看看