Scrambled Polygon(斜率排序)
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 7799 | Accepted: 3707 |
Description
A closed polygon is called convex if the line segment joining any two points of the polygon lies in the polygon. Figure 1 shows a closed polygon which is convex and one which is not convex. (Informally, a closed polygon is convex if its border doesn't have any "dents".)
The subject of this problem is a closed convex polygon in the coordinate plane, one of whose vertices is the origin (x = 0, y = 0). Figure 2 shows an example. Such a polygon will have two properties significant for this problem. The first property is that the vertices of the polygon will be confined to three or fewer of the four quadrants of the coordinate plane. In the example shown in Figure 2, none of the vertices are in the second quadrant (where x < 0, y > 0).
To describe the second property, suppose you "take a trip" around the polygon: start at (0, 0), visit all other vertices exactly once, and arrive at (0, 0). As you visit each vertex (other than (0, 0)), draw the diagonal that connects the current vertex with (0, 0), and calculate the slope of this diagonal. Then, within each quadrant, the slopes of these diagonals will form a decreasing or increasing sequence of numbers, i.e., they will be sorted. Figure 3 illustrates this point.

Input
Output
Sample Input
0 0
70 -50
60 30
-30 -50
80 20
50 -60
90 -20
-30 -40
-10 -60
90 10
Sample Output
(0,0)
(-30,-40)
(-30,-50)
(-10,-60)
(50,-60)
(70,-50)
(90,-20)
(90,10)
(80,20)
(60,30)
题意:给你一系列点,让输出一个凸多边形的各点,把斜率从大到小排序就好了;
代码;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x);
struct Node{
int x,y;
/*friend bool operator < (Node a,Node b){
if(a.x!=b.x)return a.x<b.x;
else return a.y<b.y;
}*/
}dt[100010];
int cross(Node a,Node b){
return a.x*b.y-a.y*b.x;
}
int cmp(Node a,Node b){
if(cross(a,b)>0)return 1;
else return 0;
}
int main(){
int k=0;
while(~scanf("%d%d",&dt[k].x,&dt[k].y))k++;
sort(dt+1,dt+k,cmp);
for(int i=0;i<k;i++)printf("(%d,%d)\n",dt[i].x,dt[i].y);
return 0;
}
Scrambled Polygon(斜率排序)的更多相关文章
- poj 2007 Scrambled Polygon 极角排序
/** 极角排序输出,,, 主要atan2(y,x) 容易失精度,,用 bool cmp(point a,point b){ 5 if(cross(a-tmp,b-tmp)>0) 6 retur ...
- Scrambled Polygon(凸多边形,斜率)
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7805 Accepted: 3712 ...
- 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 ...
- 【BZOJ1007】【HNOI2008】水平可见直线(斜率排序+单调栈)
1007: [HNOI2008]水平可见直线 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2605 Solved: 914[Submit][Stat ...
- poj 2007 Scrambled Polygon(极角排序)
http://poj.org/problem?id=2007 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6701 A ...
- 简单几何(极角排序) POJ 2007 Scrambled Polygon
题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * Author :Running_Time ...
- POJ 2007 Scrambled Polygon (简单极角排序)
题目链接 题意 : 对输入的点极角排序 思路 : 极角排序方法 #include <iostream> #include <cmath> #include <stdio. ...
- POJ 2007 Scrambled Polygon(简单极角排序)
水题,根本不用凸包,就是一简单的极角排序. 叉乘<0,逆时针. #include <iostream> #include <cstdio> #include <cs ...
随机推荐
- 怎样使用Markdown
转自:http://wowubuntu.com/markdown/basic.html 段落.标题.区块代码 一个段落是由一个以上的连接的行句组成,而一个以上的空行则会划分出不同的段落(空行的定义是显 ...
- 一个关于css3背景透明的例子
大家都知道使用opacity调节透明度不仅是背景透明了而且选择区域的文字也跟着透明了, 这是我们不想要的效果,于是强大的css3便有了只让背景透明的功能 那就是background:rgba(0,0, ...
- jquery.validate 一些技巧
1.Validator.element() Validates a single element, returns true if it is valid, false otherwise. http ...
- JAVA并发,CyclicBarrier
CyclicBarrier 翻译过来叫循环栅栏.循环障碍什么的(还是有点别扭的.所以还是别翻译了,只可意会不可言传啊).它主要的方法就是一个:await().await() 方法没被调用一次,计数便会 ...
- 删除windows7保留分区
在系统里以管理员运行CMD.exe键入diskpartsel disk 0 (select 选择硬盘)list vol (查看卷)sel vol 0 (选择卷,0为保留分区)inactive ( ...
- Thread-safety with regular expressions in Java
As mentioned in our introduction to the Pattern and Matcher classes, the Java regular expression API ...
- 用WebBrowser实现HTML界面的应用和交互 good
这一篇将继续讨论在使用delphi进行普通应用程序开发的时候,WebBrowser的具体应用,主要是针对使用其进行HTML界面开发的,这也是一篇我在网上找到的资料,大家如要转载,请尊重原作者的知识产权 ...
- solaris 操作系统配置联网
1. 设置主机名: etc/hostname.vmxnet0 hannick 2.设置主机名和ip地址的映射: etc/hosts 127.0.0.1 localhost 192.108.1.123 ...
- Android企业级程序完全退出的解决方案【转】
http://blog.csdn.net/wangjinyu501/article/details/8763552 问题描述 在平常开发的过程中可以发现,很多开发者对于程序的退出都没有去认真的解决.一 ...
- [置顶] 【cocos2d-x入门实战】微信飞机大战之四:飞机登场咯
转载请表明地址:http://blog.csdn.net/jackystudio/article/details/11757175 昨天收到了电子工业出版社寄过来的<cocos2d-x游戏开发之 ...