题意:如题

用Graham,直接就能得到逆时针的凸包,找到原点输出就行了,赤果果的水题~

代码:

/*
* Author: illuz <iilluzen[at]gmail.com>
* Blog: http://blog.csdn.net/hcbbt
* File: poj2007.cpp
* Create Date: 2013-11-14 18:55:37
* Descripton: convex hull
*/ #include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; #define sqr(a) ((a) * (a))
#define dis(a, b) sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)) const int MAXN = 110;
const double PI = acos(-1.0); struct Point {
int x;
int y;
Point(double a = 0, double b = 0) : x(a), y(b) {}
friend bool operator < (const Point &l, const Point &r) {
return l.y < r.y || (l.y == r.y && l.x < r.x);
}
} p[MAXN], ch[MAXN];
// p, point ch, convex hull double mult(Point a, Point b, Point o) {
return (a.x - o.x) * (b.y - o.y) >= (b.x - o.x) * (a.y - o.y);
} int Graham(Point p[], int n, Point res[]) {
int top = 1;
sort(p, p + n);
if (n == 0) return 0;
res[0] = p[0];
if (n == 1) return 0;
res[1] = p[1];
if (n == 2) return 0;
res[2] = p[2];
for (int i = 2; i < n; i++) {
while (top && (mult(p[i], res[top], res[top - 1])))
top--;
res[++top] = p[i];
}
int len = top;
res[++top] = p[n - 2];
for (int i = n - 3; i >= 0; i--) {
while (top != len && (mult(p[i], res[top], res[top - 1])))
top--;
res[++top] = p[i];
}
return top;
} int n; int main() {
while (scanf("%d%d", &p[n].x, &p[n].y) != EOF)
n++;
n = Graham(p, n, ch);
int t;
for (int i = 0; i < n; i++)
if (ch[i].x == 0 && ch[i].y == 0) {
t = i;
break;
} for (int i = t; i < n; i++)
printf("(%d,%d)\n", ch[i].x, ch[i].y);
for (int i = 0; i < t; i++)
printf("(%d,%d)\n", ch[i].x, ch[i].y);
return 0;
}

POJ 2007 Scrambled Polygon 凸包点排序逆时针输出的更多相关文章

  1. POJ 2007 Scrambled Polygon [凸包 极角排序]

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8636   Accepted: 4105 ...

  2. POJ 2007 Scrambled Polygon 凸包

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7214   Accepted: 3445 ...

  3. poj 2007 Scrambled Polygon(极角排序)

    http://poj.org/problem?id=2007 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6701   A ...

  4. POJ 2007 Scrambled Polygon 极角序 水

    LINK 题意:给出一个简单多边形,按极角序输出其坐标. 思路:水题.对任意两点求叉积正负判断相对位置,为0则按长度排序 /** @Date : 2017-07-13 16:46:17 * @File ...

  5. POJ 2007 Scrambled Polygon(简单极角排序)

    水题,根本不用凸包,就是一简单的极角排序. 叉乘<0,逆时针. #include <iostream> #include <cstdio> #include <cs ...

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

    题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * Author :Running_Time ...

  7. POJ 2007 Scrambled Polygon (简单极角排序)

    题目链接 题意 : 对输入的点极角排序 思路 : 极角排序方法 #include <iostream> #include <cmath> #include <stdio. ...

  8. poj 2007 Scrambled Polygon 极角排序

    /** 极角排序输出,,, 主要atan2(y,x) 容易失精度,,用 bool cmp(point a,point b){ 5 if(cross(a-tmp,b-tmp)>0) 6 retur ...

  9. ●POJ 2007 Scrambled Polygon

    题链: http://poj.org/problem?id=2007 题解: 计算几何,极角排序 按样例来说,应该就是要把凸包上的i点按 第三像限-第四像限-第一像限-第二像限 的顺序输出. 按 叉积 ...

随机推荐

  1. BUG(0):用某位表示特定属性

    用某个bit表示特定属性通常有两种方式: 1.指定某个特定的value #define _PAGE_VALID 0x0001 0bit 为 1 时表示此时的page entry是有效的 用法如下,此时 ...

  2. swift 总结

    结构体(struct)属于值类型, 当值类型的实例被声明为常量的时候,它的所有属性也就成了常量. 属于引用类型的类(class)则不一样.把一个引用类型的实例赋给一个常量后,仍然可以修改该实例的变量属 ...

  3. jquery全选反选

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. JDK8集合类源码解析 - LinkedList

    linkedList主要要注意以下几点: 1构造器 2 添加add(E e) 3 获取get(int index) 4 删除 remove(E e),remove(int index) 5  判断对象 ...

  5. windows下忘记mysql的root密码

    1.停止mysql 2.命令行启动mysqlmysqld --defaults-file="c:\mysql\mysql server 5.1\my.ini" --console ...

  6. jvm 启动参数设置(转载)

    JVM启动参数 http://onlyor.iteye.com/blog/1722413 博客分类: java java java启动参数共分为三类其一是标准参数(-),所有的JVM实现都必须实现这些 ...

  7. Python内置logging模块

    最近调试Python代码比较多,发现logging模块很好用. 我的用法如下: import logging logging.basicConfig(level=logging.INFO, forma ...

  8. Unity2017新功能Sprite Atlas详解

    Sprite Atlas(精灵图集)Sprite Atlas 针对现有的图集打包系统Sprite Packer在性能和易用性上的不足,进行了全面改善.除此之外,相比Sprite Packer,Spri ...

  9. Mybatis在oracle数据库中插入数据后返回自增值ID

    1.将id设置成自增序列 CREATE OR REPLACE TRIGGER "DATALIB"."TRIG_USER_ADD" BEFORE INSERT O ...

  10. DDR4 PSOD输出的优点--DBI的优点

    DDR4是JEDEC组织关于DRAM器件的下一代标准.DDR4主要是针对需要高带宽低功耗的场合.这些需求导致了DDR4芯片引入了一些新的特点,这些新的特点,导致在系统设计中,引入一些新的设计需求. D ...