zoukankan      html  css  js  c++  java
  • [POJ2007]Scrambled Polygon(计算几何 极角排序)

    题目链接:http://poj.org/problem?id=2007

    题意:给出凸包和起点,逆序输出。

    极角排序可以用反三角函数求出角度,按照角度排序。也可以用叉乘来做。注意题目说给定第一个数据是0,0,这是凸包的起点,数据中有在x轴负半轴的数据,所以排序的时候0,0要跳过。只排1~n-1个坐标。

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <iomanip>
     4 #include <cstring>
     5 #include <climits>
     6 #include <complex>
     7 #include <fstream>
     8 #include <cassert>
     9 #include <cstdio>
    10 #include <bitset>
    11 #include <vector>
    12 #include <deque>
    13 #include <queue>
    14 #include <stack>
    15 #include <ctime>
    16 #include <set>
    17 #include <map>
    18 #include <cmath>
    19 
    20 using namespace std;
    21 
    22 typedef struct Point {
    23     int x;
    24     int y;
    25     Point() {}
    26     Point(int xx, int yy) : x(xx), y(yy) {}
    27     Point operator +(const Point& b) const { return Point(x+b.x, y+b.y); }
    28     Point operator -(const Point& b) const { return Point(x-b.x, y-b.y); }
    29     int operator ^(const Point& b) const { return x * b.y - y * b.x; }
    30     int operator *(const Point& b) const { return x * b.x + y * b.y; }
    31 }Point;
    32 
    33 typedef struct Line {
    34     Point u;
    35     Point v;
    36     Line() {}
    37     Line(Point uu, Point vv) : u(uu), v(vv) {}
    38 }Line;
    39 
    40 int xmulti(Point p0, Point p1, Point p2) {
    41     return (p1 - p0) ^ (p2 - p0);
    42 }
    43 
    44 const int maxn = 111;
    45 Point pp[maxn];
    46 int n;
    47 
    48 int cmp(Point a, Point b) {
    49     Point t(0, 0);
    50     return xmulti(t, b, a) < 0;
    51 }
    52 
    53 int main() {
    54     // freopen("in", "r", stdin);
    55     for(n = 0; ~scanf("%d %d", &pp[n].x, &pp[n].y); n++);
    56     sort(pp+1, pp+n, cmp);
    57     for(int i = 0; i < n; i++) {
    58         printf("(%d,%d)
    ", pp[i].x, pp[i].y);
    59     }
    60     return 0;
    61 }
  • 相关阅读:
    动手动脑
    加减乘除
    测试
    Java学习的第五十六天
    Java学习的第五十五天
    js判断一个时间是否在某一个时间段内
    js计算两个时间相差多少分钟
    js分钟转化为小时并且以某个数字进行递增
    关于Js debounce(防抖)函数和throttle(节流)小结
    webpack配置scss
  • 原文地址:https://www.cnblogs.com/kirai/p/5208089.html
Copyright © 2011-2022 走看看