题意:如题

用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;
}

最新文章

  1. 当我们在谈论kmeans(2)
  2. iOS开发之窥探UICollectionViewController(二) --详解CollectionView各种回调
  3. PAT Mooc datastructure 6-1
  4. Thinkpad T420 指纹开机 win10 解决方案
  5. 获取或者设置时,无后缀和A后缀和W后缀的区别
  6. 剑指Offer23 二叉树中和为sum的路径
  7. hornetq 入门(1)
  8. Angularjs 整体框架结构
  9. MSSQL 如何实现 MySQL 的 limit 查询方式 (转)
  10. MVC小系列(十八)【给checkbox和radiobutton添加集合的重载】
  11. [转]3proxy 二级代理配置样例
  12. 微信小程序开发之入门篇(熟悉项目结构)
  13. poj 2309
  14. [ACM] 九度OJ 1553 时钟
  15. Css 之 px em %
  16. Struts2漏洞解决
  17. php7安装 event扩展
  18. MT【207】|ax^2+bx+c|中判别式$\Delta$的含义
  19. JavaScript+CSS+DIV实现表格变色示例
  20. active在iphone上不起作用

热门文章

  1. Java的反射技术
  2. XSS绕过速查表
  3. Visual code 搭建Vue项目
  4. MySQL复制(Replication)
  5. ros主从关系
  6. .net调用word转换pdf出现80080005错误的解决办法
  7. redis2
  8. c#中的as,is和强转
  9. 一窥kbmmw中的 smart service
  10. Java的GUI设计中如何跨界面传值