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);
}

转载于:https://www.cnblogs.com/MalcolmMeng/p/10181773.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值