codeforces 257 C. View Angle

题目:http://codeforces.com/contest/257/problem/C

极角序。使用atan2(y,x)排序。

这题很容易做错的一点就是开始会想到直接用sort升序排序后,最大减去最小即是所求,其实这是不对的。比如给三点:(-1,-1),(-1,1),(-1,2)测一下。

每个黄色区域的两边上的两点肯定是相邻的,我们可以根据这个已知项来解答:

本题我觉得还是很有思维性的。

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;

struct Point
{
    double x;
    double y;
    double angle;
};
Point p[100003];
bool cmp(Point a,Point b)
{
    return a.angle<b.angle;
}
int main()
{
    int n;
    scanf(" %d",&n);
    for(int i=0; i<n; i++)
    {
        scanf(" %lf %lf",&p[i].x,&p[i].y);
        p[i].angle = atan2(p[i].y,p[i].x);
    }
    sort(p,p+n,cmp);
    p[n].angle = p[0].angle + 2 * acos(-1.0);
    double ans = 2*acos(-1.0);

    for(int i=0; i<n; i++)
    {
        ans = min(ans,2 * acos(-1.0) - fabs(p[i+1].angle - p[i].angle));
    }
    printf("%lf\n",ans*180.0/acos(-1.0));
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值