Scrambled Polygon---poj2007(利用叉积排序)
题目链接:http://poj.org/problem?id=2007
题意:乱序给出凸多边形的顶点坐标,要求按逆时 针顺序输出各顶点。给的第一个点一定是 (0,0),没有其他点在坐标轴上,没有三点 共线的情况。
可以运用叉积进行排序,矢量p1×p2 > 0说明p1逆时针旋转<180度可以得到p2;
/*乱序给出凸多边形的顶点坐标,要求按逆时针顺序输出各顶点。给的第一个点一定是(0,0),没有其他点在坐标轴上,没有三点共线的情况。*/
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int N = ;
struct point
{
double x, y;
point(){}
point(double x_, double y_): x(x_), y(y_) {}
point friend operator - (const point &p1, const point &p2)///矢量p2p1;
{
return point(p1.x-p2.x, p1.y-p2.y);
}
double friend operator ^ (const point &p1, const point &p2)
{
return p1.x*p2.y - p1.y*p2.x;
///p1×p2: >0说明p1逆时针旋转<180度可得到p2;
}
};
int cmp(point p1, point p2)
{
if( ((p1-point(,)) ^ (p2-point(,))) > )
return ;
return ;
}
point a[N];
int n;
int main()
{
n = ;
while(scanf("%lf %lf", &a[n].x, &a[n].y)!=EOF) n++;
sort(a+, a+n, cmp);
for(int i=; i<n; i++)
cout<<"("<<a[i].x<<","<<a[i].y<<")"<<endl;
return ;
}
Scrambled Polygon---poj2007(利用叉积排序)的更多相关文章
- POJ 2007 Scrambled Polygon (简单极角排序)
题目链接 题意 : 对输入的点极角排序 思路 : 极角排序方法 #include <iostream> #include <cmath> #include <stdio. ...
- POJ 2007 Scrambled Polygon(简单极角排序)
水题,根本不用凸包,就是一简单的极角排序. 叉乘<0,逆时针. #include <iostream> #include <cstdio> #include <cs ...
- Scrambled Polygon POJ - 2007 极角排序
题意: 给你n个点,这n个点可以构成一个多边形(但是不是按顺序给你的).原点(0,0)为起点,让你按顺序逆序输出所有点 题解: 就是凸包问题的极角排序 用double一直Wa,改了int就可以了 // ...
- poj 2007 Scrambled Polygon(极角排序)
http://poj.org/problem?id=2007 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6701 A ...
- POJ 2007 Scrambled Polygon [凸包 极角排序]
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8636 Accepted: 4105 ...
- Scrambled Polygon(斜率排序)
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7799 Accepted: 3707 ...
- POJ 2007 Scrambled Polygon 凸包
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7214 Accepted: 3445 ...
- poj 1654(利用叉积求面积)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17937 Accepted: 4957 Description ...
- poj2007(极角排序)
利用叉积按照逆时针方向进行极角排序, #define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<algorithm&g ...
随机推荐
- BZOJ3799 : 字符串重组
从大到小枚举答案与T串的lcp,然后贪心 #include<cstdio> #include<cstring> char s[5010],t[5010],ans[5010]; ...
- BZOJ 1121 & science
1121: [POI2008]激光发射器SZK Time Limit: 10 Sec Memory Limit: 162 MB Submit: 647 Solved: 537 [Submit][Sta ...
- NOIP200003方格取数
NOIP200003方格取数 难度级别: D: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 XYZ 是首师大附中信息技术团编 ...
- 深入理解JVM—性能监控工具
(转自:http://yhjhappy234.blog.163.com/blog/static/31632832201222691738865/) 我们知道,在JVM编译期和加载器,甚至运行期已经做了 ...
- <html:option获取文本值
<p class="w120">变更后IP:</p> <div class="comBobox w200 f_l"> < ...
- Leetcode | Work Break I & II
Work Break I Given a string s and a dictionary of words dict, determine if s can be segmented into a ...
- LightOJ 1188 Fast Queries(简单莫队)
1188 - Fast Queries PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 64 MB Gi ...
- 安装pypcap = 安装flex:the fast lexical analyser + 安装libpcap-1.7.4
flex flex is a tool for generating scanners 安装flex-2.6.0安装包 网址:https://sourceforge.net/projects/flex ...
- 使用webdriver + phantomjs + pdfkit 生成PDF文件
实例 #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on Dec 6, 2013 @author: Jay <smile665@gm ...
- PHP开发绝对不能违背的安全铁则
PHP开发绝对不能违背的安全铁则 [来源] 达内 [编辑] 达内 [时间]2012-12-27 使用 mysql_real_escape_string() 作为用户输入的包装器,就可以避免用 ...