POJ 2007 Scrambled Polygon 凸包点排序逆时针输出
题意:如题
用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 凸包点排序逆时针输出的更多相关文章
- POJ 2007 Scrambled Polygon [凸包 极角排序]
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8636 Accepted: 4105 ...
- POJ 2007 Scrambled Polygon 凸包
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7214 Accepted: 3445 ...
- poj 2007 Scrambled Polygon(极角排序)
http://poj.org/problem?id=2007 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6701 A ...
- POJ 2007 Scrambled Polygon 极角序 水
LINK 题意:给出一个简单多边形,按极角序输出其坐标. 思路:水题.对任意两点求叉积正负判断相对位置,为0则按长度排序 /** @Date : 2017-07-13 16:46:17 * @File ...
- POJ 2007 Scrambled Polygon(简单极角排序)
水题,根本不用凸包,就是一简单的极角排序. 叉乘<0,逆时针. #include <iostream> #include <cstdio> #include <cs ...
- 简单几何(极角排序) POJ 2007 Scrambled Polygon
题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * Author :Running_Time ...
- POJ 2007 Scrambled Polygon (简单极角排序)
题目链接 题意 : 对输入的点极角排序 思路 : 极角排序方法 #include <iostream> #include <cmath> #include <stdio. ...
- poj 2007 Scrambled Polygon 极角排序
/** 极角排序输出,,, 主要atan2(y,x) 容易失精度,,用 bool cmp(point a,point b){ 5 if(cross(a-tmp,b-tmp)>0) 6 retur ...
- ●POJ 2007 Scrambled Polygon
题链: http://poj.org/problem?id=2007 题解: 计算几何,极角排序 按样例来说,应该就是要把凸包上的i点按 第三像限-第四像限-第一像限-第二像限 的顺序输出. 按 叉积 ...
随机推荐
- c#不同数组之间的转换【转载,消化自动删除】
c#中从string数组转换到int数组 string[] input = { "1", "2", "3", "4", ...
- MFC窗口位置和大小的获取
最近在做一个项目,需要控件随对话框大小的变化而变化,因此需要准确获取对话框窗口.控件的大小和位置. 经过好一番查寻.测试,终于看到了希望.下面是一些获取窗口位置和大小的函数,示例如下: 1.获取屏幕分 ...
- NOIP需要掌握的内容(大致
1.排序算法(快排.选择.冒泡.堆排序.二叉排序树.桶排序)2.DFS/BFS 剪枝 哈希表3.树 ①遍历 ②二叉树 ③二叉排序树(查找.生成.删除) ④堆(二叉堆.左偏树.堆排序) ...
- MySQL学习笔记-数据库内存
数据库内存 InnoDB存储引擎内存由以下几个部分组成:缓冲池(buffer pool).重做日志缓冲池(redo log buffer)以及额外的内存池(additional memory pool ...
- UI设计教程:关于版式设计
版式设计是视觉传达的重要手段之一,版式设计,即把有限的视觉元素在版面页进行有效的视觉组合,最优化地传达信息的同时,去影响受众,使受众产生视觉上的美感. 版式设计基本流程 在进行版式设计时,设计作品的 ...
- UI设计教程分享:设计一个高质量的logo要从哪方面入手呢?
有的人觉得logo只是一个简单的图形,对品牌影响无关紧要:但有的人却觉得logo对品牌有较大的影响.其实logo承载着一个公司的品牌形象.公司背景.公司理念等.就像Landor往往给一个企业做logo ...
- where_1
(二)WHERE //where不单独使用,与match,optional match,start,with搭配 where 与match,optional match 一起用,表示约束 where ...
- robot framework 中should be true 与should contain 的区别
should be true 是否等于:判断是否should contain 是否包含 a是否包含b
- 常用jvm参数
如果你是Eclipse ,可以通过 run -> Run Configurations->Arguments 添加-XX:+PrintGCDetails 打开gc日志 -Xmx 设置jav ...
- activiti5.22整合modeler时出错TypeError: Cannot read property 'split' of undefined
activiti5.22.0整合modeler时,打开的流程页面不显示工具栏和左边的控件栏,产生如下的错误: TypeError: Cannot read property 'split' of un ...