zoukankan      html  css  js  c++  java
  • poj2007

    极坐标排序

    注意atan2(y,x)的使用方法,y在前,x在后。返回X轴正方向到原点到(x,y)点的射线的到角。

    View Code
    #include <iostream>
    #include
    <cstdlib>
    #include
    <cstring>
    #include
    <cstdio>
    #include
    <cmath>
    #include
    <algorithm>
    using namespace std;

    #define maxn 55
    #define pi acos(-1)

    struct Point
    {
    int x, y;
    } point[maxn];

    bool operator <(const Point &a, const Point &b)
    {
    return atan2(a.y, a.x) < atan2(b.y, b.x);
    }

    double cal(double a)
    {
    if (a < 0)
    return a + 2 * pi;
    return a;
    }

    int main()
    {
    //freopen("t.txt", "r", stdin);
    scanf("%d%d", &point[0].x, &point[0].y);
    int n = 0;
    while (scanf("%d%d", &point[n].x, &point[n].y) != EOF)
    n
    ++;
    sort(point, point
    + n);
    double temp = 0;
    point[n]
    = point[0];
    int s;
    for (int i = 0; i < n; i++)
    {
    double a = cal(atan2(point[i + 1].y, point[i + 1].x) - atan2(point[i].y, point[i].x));
    if (a > temp)
    {
    temp
    = a;
    s
    = (i + 1) % n;
    }
    }
    printf(
    "(0,0)\n");
    for (int i = 0; i < n; i++)
    printf(
    "(%d,%d)\n", point[(s + i) % n].x, point[(s + i) % n].y);
    return 0;
    }

  • 相关阅读:
    无旋转Treap简介
    bzoj 4318 OSU!
    bzoj 1419 Red is good
    bzoj 4008 亚瑟王
    bzoj 1014 火星人prefix
    更多的莫队
    bzoj 3489 A simple rmq problem
    洛谷 2056 采花
    NOIP 2017 游(划水)记
    UVa 11997 K Smallest Sums
  • 原文地址:https://www.cnblogs.com/rainydays/p/2163310.html
Copyright © 2011-2022 走看看