题意:如题

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

代码:

  1. /*
  2. * Author: illuz <iilluzen[at]gmail.com>
  3. * Blog: http://blog.csdn.net/hcbbt
  4. * File: poj2007.cpp
  5. * Create Date: 2013-11-14 18:55:37
  6. * Descripton: convex hull
  7. */
  8.  
  9. #include <cstdio>
  10. #include <cstring>
  11. #include <cmath>
  12. #include <algorithm>
  13. using namespace std;
  14.  
  15. #define sqr(a) ((a) * (a))
  16. #define dis(a, b) sqrt(sqr(a.x - b.x) + sqr(a.y - b.y))
  17.  
  18. const int MAXN = 110;
  19. const double PI = acos(-1.0);
  20.  
  21. struct Point {
  22. int x;
  23. int y;
  24. Point(double a = 0, double b = 0) : x(a), y(b) {}
  25. friend bool operator < (const Point &l, const Point &r) {
  26. return l.y < r.y || (l.y == r.y && l.x < r.x);
  27. }
  28. } p[MAXN], ch[MAXN];
  29. // p, point ch, convex hull
  30.  
  31. double mult(Point a, Point b, Point o) {
  32. return (a.x - o.x) * (b.y - o.y) >= (b.x - o.x) * (a.y - o.y);
  33. }
  34.  
  35. int Graham(Point p[], int n, Point res[]) {
  36. int top = 1;
  37. sort(p, p + n);
  38. if (n == 0) return 0;
  39. res[0] = p[0];
  40. if (n == 1) return 0;
  41. res[1] = p[1];
  42. if (n == 2) return 0;
  43. res[2] = p[2];
  44. for (int i = 2; i < n; i++) {
  45. while (top && (mult(p[i], res[top], res[top - 1])))
  46. top--;
  47. res[++top] = p[i];
  48. }
  49. int len = top;
  50. res[++top] = p[n - 2];
  51. for (int i = n - 3; i >= 0; i--) {
  52. while (top != len && (mult(p[i], res[top], res[top - 1])))
  53. top--;
  54. res[++top] = p[i];
  55. }
  56. return top;
  57. }
  58.  
  59. int n;
  60.  
  61. int main() {
  62. while (scanf("%d%d", &p[n].x, &p[n].y) != EOF)
  63. n++;
  64. n = Graham(p, n, ch);
  65. int t;
  66. for (int i = 0; i < n; i++)
  67. if (ch[i].x == 0 && ch[i].y == 0) {
  68. t = i;
  69. break;
  70. }
  71.  
  72. for (int i = t; i < n; i++)
  73. printf("(%d,%d)\n", ch[i].x, ch[i].y);
  74. for (int i = 0; i < t; i++)
  75. printf("(%d,%d)\n", ch[i].x, ch[i].y);
  76. return 0;
  77. }

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. c#不同数组之间的转换【转载,消化自动删除】

    c#中从string数组转换到int数组 string[] input = { "1", "2", "3", "4", ...

  2. MFC窗口位置和大小的获取

    最近在做一个项目,需要控件随对话框大小的变化而变化,因此需要准确获取对话框窗口.控件的大小和位置. 经过好一番查寻.测试,终于看到了希望.下面是一些获取窗口位置和大小的函数,示例如下: 1.获取屏幕分 ...

  3. NOIP需要掌握的内容(大致

    1.排序算法(快排.选择.冒泡.堆排序.二叉排序树.桶排序)2.DFS/BFS 剪枝 哈希表3.树   ①遍历   ②二叉树   ③二叉排序树(查找.生成.删除)   ④堆(二叉堆.左偏树.堆排序)  ...

  4. MySQL学习笔记-数据库内存

    数据库内存 InnoDB存储引擎内存由以下几个部分组成:缓冲池(buffer pool).重做日志缓冲池(redo log buffer)以及额外的内存池(additional memory pool ...

  5. UI设计教程:关于版式设计

    版式设计是视觉传达的重要手段之一,版式设计,即把有限的视觉元素在版面页进行有效的视觉组合,最优化地传达信息的同时,去影响受众,使受众产生视觉上的美感. 版式设计基本流程  在进行版式设计时,设计作品的 ...

  6. UI设计教程分享:设计一个高质量的logo要从哪方面入手呢?

    有的人觉得logo只是一个简单的图形,对品牌影响无关紧要:但有的人却觉得logo对品牌有较大的影响.其实logo承载着一个公司的品牌形象.公司背景.公司理念等.就像Landor往往给一个企业做logo ...

  7. where_1

    (二)WHERE //where不单独使用,与match,optional match,start,with搭配 where 与match,optional match 一起用,表示约束 where ...

  8. robot framework 中should be true 与should contain 的区别

    should be true  是否等于:判断是否should contain  是否包含 a是否包含b

  9. 常用jvm参数

    如果你是Eclipse ,可以通过 run -> Run Configurations->Arguments 添加-XX:+PrintGCDetails 打开gc日志 -Xmx 设置jav ...

  10. activiti5.22整合modeler时出错TypeError: Cannot read property 'split' of undefined

    activiti5.22.0整合modeler时,打开的流程页面不显示工具栏和左边的控件栏,产生如下的错误: TypeError: Cannot read property 'split' of un ...