poj 2007 Scrambled Polygon(凸包Graham扫描线模板)
来源:互联网 发布:淘宝发票规则 编辑:程序博客网 时间:2024/06/05 23:17
Scrambled Polygon
题目链接:http://poj.org/problem?id=2007
代码如下:
#include<stdio.h>#include<limits.h>#include<stdlib.h>#include<string.h>#include<deque>#include<algorithm>using namespace std;typedef struct{int x;int y;}Point;int n, temp;Point top1, top2, s[105];deque<Point> q;bool comp2(Point a, Point b)//按幅角排序{if((a.x-top1.x)*(b.y-top1.y)-(a.y-top1.y)*(b.x-top1.x)>0)return 1;else if((a.x-top1.x)*(b.y-top1.y)-(a.y-top1.y)*(b.x-top1.x)==0 && abs(a.x-top1.x)<abs(b.x-top1.x))return 1;return 0;}int main(void){n=1;int ax,ay;ax = ay = INT_MAX;while(~scanf("%d%d", &s[n].x, &s[n].y)){ n++; if(s[n].y<ay || s[n].y==ay && s[n].x<ax) //每次记录最左下角的,先下后左 temp = n, ay = s[n].y, ax = s[n].x;} top1 = s[temp]; //作为sort排序的比较标准 sort(s+1, s+n, comp2); q.push_back(s[1]); q.push_back(s[2]); temp = 3; while(temp<n) { top1 = q.back(); q.pop_back();//临时弹出用作判定 top2 = q.back(); if((top2.x-top1.x)*(s[temp].y-top1.y)-(top2.y-top1.y)*(s[temp].x-top1.x)<=0) { q.push_back(top1);//符合条件,临时弹出的归队 q.push_back(s[temp]);//当前点入队 temp++;//下一个点作为当前点 } //不符合条件丢弃 } int flag=0; while(q.empty()==0) { top1 = q.front(); if((top1.x==0 && top1.y==0) || flag)//根据题意,循环入栈出栈,判断从(0,0)开始输出 { printf("(%d,%d)\n", top1.x, top1.y); q.pop_front(); flag=1; } else if(!flag) { q.pop_front(); q.push_back(top1); } }return 0;}
阅读全文
0 0
- poj 2007 Scrambled Polygon(凸包Graham扫描线模板)
- POJ 2007 Scrambled Polygon(凸包)
- 【凸包 Graham法 极角排序】poj 2007 Scrambled Polygon
- POJ 2007 Scrambled Polygon(凸包)
- POJ 2007 Scrambled Polygon(凸包)
- POJ 2007 Scrambled Polygon (凸包输出点路径)
- poj Scrambled Polygon 2007 (凸包基础点排序)
- Poj.2007 Scrambled Polygon【凸包】 2015/09/02
- poj 2007 Scrambled Polygon
- poj 2007 Scrambled Polygon
- POJ 2007 Scrambled Polygon
- POJ 2007 Scrambled Polygon
- POJ 2007 Scrambled Polygon
- POJ 2007 Scrambled Polygon
- POJ 2007 Scrambled Polygon
- poj 2007 Scrambled Polygon
- POJ 2007 Scrambled Polygon .
- POJ 2007 Scrambled Polygon
- DataPicker和TimePicker
- Java 中带参带返回值方法的使用
- 芬伯格主张计算机设计重构计算机技术
- codevs 2059逃出克隆岛
- 【理解HotSpot虚拟机】串行垃圾收集器Serial和Serial Old原理
- poj 2007 Scrambled Polygon(凸包Graham扫描线模板)
- poj2031 Building a Space Station
- 题目491:幸运三角形
- 你是怎样搭建.net架构
- oracle函数——通用函数
- SPRINGMVC注解之@RESPONSEBODY和@REQUESTBODY详解
- Java中方法的重载
- Java学习笔记 11 instanceof 、equal 和 == 的联系和区别
- Servlet学习笔记—Servlet接口和HttpServlet类