题目链接: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(利用叉积排序)的更多相关文章

  1. POJ 2007 Scrambled Polygon (简单极角排序)

    题目链接 题意 : 对输入的点极角排序 思路 : 极角排序方法 #include <iostream> #include <cmath> #include <stdio. ...

  2. POJ 2007 Scrambled Polygon(简单极角排序)

    水题,根本不用凸包,就是一简单的极角排序. 叉乘<0,逆时针. #include <iostream> #include <cstdio> #include <cs ...

  3. Scrambled Polygon POJ - 2007 极角排序

    题意: 给你n个点,这n个点可以构成一个多边形(但是不是按顺序给你的).原点(0,0)为起点,让你按顺序逆序输出所有点 题解: 就是凸包问题的极角排序 用double一直Wa,改了int就可以了 // ...

  4. poj 2007 Scrambled Polygon(极角排序)

    http://poj.org/problem?id=2007 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6701   A ...

  5. POJ 2007 Scrambled Polygon [凸包 极角排序]

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8636   Accepted: 4105 ...

  6. Scrambled Polygon(斜率排序)

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7799   Accepted: 3707 ...

  7. POJ 2007 Scrambled Polygon 凸包

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7214   Accepted: 3445 ...

  8. poj 1654(利用叉积求面积)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17937   Accepted: 4957 Description ...

  9. poj2007(极角排序)

    利用叉积按照逆时针方向进行极角排序, #define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<algorithm&g ...

随机推荐

  1. jQuery Event.delegateTarget 属性详解

    // 为id为element的元素中的所有span元素绑定click事件 $("#element").on( "click", "span" ...

  2. js对象数组按属性快速排序

    前一篇<关于selector性能比赛>中提到,目测觉得在$("div,p,a")这样有逗号时,sizzle耗时异常(600多个元素,花了200ms),说是它可能没有优化 ...

  3. JSON转换为数组 但读取JSON的顺序目前没法保证

    var json = {a : 1, b : 2, c: 3}; var jsonArr = []; for (i in json){ var wrap = []; wrap[0] = i; wrap ...

  4. 响应式HTML5+CSS3 网站开发测试实践

    仅仅利用media query适配样式是远远不够的,并没有考虑触屏下的行为和特有的内容组织方式的不同.简单在桌面版基础上叠加mobile版的代码,会带来请求增多.流量.性能.代码冗余等诸多方面问题.有 ...

  5. ios batchRequest

    https://github.com/facebook/pop AF 为什么要用 一个线程去进行  1.这有什么好处  因为其生产额外的线程也要 开销的   asi 和af都是这么去做的  2.本身所 ...

  6. OpenCV2.4.10 Mac Qt Configuration

    Download OpenCV 2.4.10 Download CMake 2.8 Open CMake and choose the source code directory and build ...

  7. hdu Wooden Sticks

    这题是暴力加贪心,算是一道水题吧!只要把l和w从小到大排个序就行了... #include"iostream" #include"stdio.h" #inclu ...

  8. Swift UICollectionView 简单使用

    最近要研究下排布的游戏关卡界面的实现,简单做了个UICollectionView的demo. 先看最后的效果: 下面来看实现的方法把,在Storyboard对应的ViewController中增加一个 ...

  9. mysql 商品表的设计思路(面向对象建表:类与对象)

    学习地址 http://www.jtthink.com/course/play/352 商品通用信息主表:prop_main 不仔细多说,正常业务都会涉及到并且考虑的相对周全.常用字段[商品id][商 ...

  10. [转].net中的认证(authentication)与授权(authorization)

    本文转自:http://www.cnblogs.com/yjmyzz/archive/2010/08/29/1812038.html 注:这篇文章主要给新手看的,老手们可能会觉得没啥营养,就请绕过吧. ...