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);
    }
    
    
  • 相关阅读:
    07组合,模版
    06享元、责任链
    05观察,命令
    04代理,迭代器
    03单例,策略
    02工厂,创建者
    01基础
    css随记02布局
    css随记01编辑技巧,背景与边框
    nodejs随记03
  • 原文地址:https://www.cnblogs.com/MalcolmMeng/p/10181773.html
Copyright © 2011-2022 走看看