hdu 3532 Max Angle

1. atan2(y,x)返回值在 -pi 到 pi 之间。要划区间
2.当两线段夹角 angel > pi 时 , 取 angle = 2Pi - angle .
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
#define FOR(i,s,e) for (int (i)=(s);(i)<(e);i++)
const double INF  = 1E20;
const double eps = 1E-10;
const int  MAXV = 300;
const double PI  = 3.1415926535897932384626;
/* 基本几何结构 */
struct POINT
{
 double x;
 double y;
 POINT(double a=0, double b=0) { x=a; y=b;} //constructor
};

double myatan2(double y,double x)
{
    double t = atan2(y,x);

    return t >= 0 ? t : t + 2*PI;
}
double angle[1010];
POINT p[1011];
int main()
{
    int n;
    // freopen("in.txt","r",stdin);
    while (scanf("%d",&n),n>0)
    {
        FOR(i,0,n)
        {
            scanf("%lf%lf",&p[i].x,&p[i].y);
        }
        double max = -500;
        FOR(i,0,n)
        {
            int num = 0;
            FOR(j,0,n)
            if (i != j)
            angle[num++] = myatan2(p[i].y-p[j].y,p[i].x-p[j].x);
            sort(angle,angle+num);
            double min = INF;
            FOR(j,0,num-1)
            {
                double a = angle[j+1]-angle[j] < PI ? angle[j+1]-angle[j] : 2*PI-angle[j+1]-angle[j];
                if (min > a)
                min = a;
            }

            if (min > max)
            max = min ;

        }
        printf("%.4lf\n",fabs(max/PI*180));
    }
    return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值