题目链接: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. BZOJ4304 : 道路改建

    首先求出SCC,把图缩点成一个DAG. 通过拓扑排序+DP求出: dp0[x]:从x点出发能到的点的集合. dp1[x]:能到x的点的集合. 对于一条边x->y,将它改为双向边后,形成的新的SC ...

  2. APIO2015

    还没有写完APIO2015的题目,打算今天写一写. T1: 按位DP,DP时要保证已确定的位为0. 前4组设f[n][k]表示把前n个分成k组是否合法. 最后一组设g[n]表示把前n个最少分为多少组才 ...

  3. COJ977 WZJ的数据结构(负二十三)

    试题描述 输入一个字符串S,输出S的最长连续回文子串长度. 输入 输入一个字符串S. 输出 输出S的最长连续回文子串长度 输入示例 abacbbc 输出示例 4 其他说明 1<=|S|<= ...

  4. JS。 问题类型:穷举,迭代。两个关键词:break和continue

    问题类型: 穷举:(在不知道什么情况下是我们需要的结果的时候只能够让它一个一个都给走一遍) 百鸡百钱:公鸡1钱,母鸡2钱,小鸡0.5钱. 思路: 公鸡买100只,母鸡,小鸡都是0只: 母鸡50只,公鸡 ...

  5. 又一种Mysql报错注入

    from:https://rdot.org/forum/showthread.php?t=3167 原文是俄文,所以只能大概的翻译一下 这个报错注入主要基于Mysql的数据类型溢出(不适用于老版本的M ...

  6. ubuntu 14.04安装

    最近想搞spark.没有集群环境,想先在单机上跑.但是两年前一直用到现在的virtualbox已经太老,很多源都停更了.所以准备装ubuntu14.04. 0. 更新源.163的源有问题,用的是soh ...

  7. 字符串&数组的相互转换

    字符串 -> 数组 方法一: $str = "abcd" $s2 = $str.GetEnumerator()  #$s2是无法使用下标的方式进行索引的,因为其不是array ...

  8. 获取某个Group中所有对象的DisplayName

    $SANs = Get-ADGroupMember -Identity "CN=gAPCHN-HGZ-IE10-Users,OU=Groups,OU=Hangzhou - China,OU= ...

  9. optimize table table_name myisam mysql自动清除删除过留下的空记录

    optimize table table_name 这个可以清除你表里面的空记录,每次清除的时候记得锁表 lock tables table_name  write|read; unlock tabl ...

  10. 安装wamp,访问主页提示PHP configuration loaded file……

    安装wamp,访问主页提示PHP configuration loaded file…… *** ERROR *** The PHP configuration loaded file is: - s ...