[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)\n", pp[i].x, pp[i].y);
59     }
60     return 0;
61 }
时间: 2024-11-10 08:19:59

[POJ2007]Scrambled Polygon(计算几何 极角排序)的相关文章

poj 2007 Scrambled Polygon(极角排序)

http://poj.org/problem?id=2007 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6701   Accepted: 3185 Description A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments ar

POJ2007 Scrambled Polygon

PS: 此题可以用凸包做,也可以用极角排序,关键是理解排序原理,题目说不会出现三点共线的情况.(Window 64bit %I64d, Linux %lld) #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <cmath> using namespace std; struc

hdu-5784 How Many Triangles(计算几何+极角排序)

题目链接: How Many Triangles Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 570    Accepted Submission(s): 183 Problem Description Alice has n points in two-dimensional plane. She wants to know ho

HDU 3532 Max Angle(计算几何——极角排序)

传送门 Max Angle Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 704    Accepted Submission(s): 253 Problem Description Given many points in a plane, two players are playing an interesting game. Pl

POJ Transmitters(计算几何 极角排序啊)

题目链接:http://poj.org/problem?id=1106 Description In a wireless network with multiple transmitters sending on the same frequencies, it is often a requirement that signals don't overlap, or at least that they don't conflict. One way of accomplishing thi

【计算几何+极角排序+爆ll】E. Convex

https://www.bnuoj.com/v3/contest_show.php?cid=9147#problem/E [题意] 给定n个点的坐标,可以选择其中的四个点构造凸四边形,问最多能构造多少个凸四边形? [思路] 凸四边形的个数等于C(n,4)-凹四边形的个数. 凹四边形的特点是有一个顶点被另外三个顶点围成的三角形包了起来. 所以现在的问题就是找凹四边形. 我们可以枚举每个点,作为被三角形包围的中心点o.怎么找这样包围中心点的三角形? 这样的三角形一定是在存在一条经过中心点的直线,三角

poj 2007 Scrambled Polygon 极角排序

1 /** 2 极角排序输出,,, 3 主要atan2(y,x) 容易失精度,,用 4 bool cmp(point a,point b){ 5 if(cross(a-tmp,b-tmp)>0) 6 return 1; 7 if(cross(a-tmp,b-tmp)==0) 8 return length(a-tmp)<length(b-tmp); 9 return 0; 10 } 11 **/ 12 #include <iostream> 13 #include <algo

Scrambled Polygon POJ - 2007(极角排序)

Scrambled Polygon POJ - 2007 题意: 思路:其实就是将(0,0)这个点按照极角排序,其他点对于(0,0)来排序,将排序后输出就行,注意输入不定 1 // 2 // Created by HJYL on 2020/1/17. 3 // 4 #include<iostream> 5 #include<cstring> 6 #include<cstdio> 7 #include<cmath> 8 #include<algorith

简单几何(极角排序) POJ 2007 Scrambled Polygon

题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * Author :Running_Time * Created Time :2015/11/3 星期二 14:46:47 * File Name :POJ_2007.cpp ************************************************/ #include <cstdio> #include <al