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 ...
随机推荐
- cocos2d-x学习日志(12) --弹出对话框的设计与实现
我们时常需要这么些功能,弹出一个层,给与用户一些提示,这也是一种模态窗口,在没有对当前对话框进行确认的时候,不能继续往下操作. 功能分析 我们设计一个对话框,对话框上有几个按钮(个数可定制),当然有个 ...
- ExpandableListView 箭头样式
ExpandableListVivew是ListView的子类,它在普通ListView的基础上进行了扩展,它把应用中的列表项分为几组,每组里 又可包含多个列表项.ExpandableListVive ...
- mysql 简单游标
<=====================MYSQL 游标示例=====================> CREATE PROCEDURE `test`.`new_procedure` ...
- FileNameExtensionFilter文件过滤
package com.soft.test; import javax.swing.*; import javax.swing.filechooser.*; import java.awt.event ...
- C# WINFORM 线程中更新UI
幸好今天是周末,有时间把这个问题记录一下.在多种语言之间切换,发现开发效率降的很低了,开发成本都集中到调式上了,C/C++这些放弃很久了,突然感觉线程这个问题搞的有点烦躁 我这里提到的线程中更新UI, ...
- 在Linux下使用iconv转换字符串编码
在Linux下写C程序,尤其是网络通信程序时经常遇到编码转换的问题,这里要用到iconv函数库. iconv函数库有以下三个函数 123456 #include <iconv.h>icon ...
- 使用自定义脚本扩展程序自动执行 VM 自定义任务
在 Build 开发者大会上推出VM 扩展程序的其中一个称为"自定义脚本扩展程序",它支持 PowerShell.如果这是您第一次访问这些博客,可能需要查看以前的博客,请单击 ...
- HDU 5446 Unknown Treasure(Lucas定理+CRT)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5446 [题目大意] 给出一个合数M的每一个质因子,同时给出n,m,求C(n,m)%M. [题解] ...
- java的控制流程
1.顺序结构顺序结构就是指按语句执行的先后顺序,或者说语句出现的先后顺序逐条执行程序语句.语句块,完全是按照程序平台的执行约定进行的,比如第一个 HelloWorld程序:public class H ...
- tocken和ticket的数据模型;
/* jshint -W079 */ /* jshint -W020 */ "use strict"; var _ = require("lodash"); m ...