题目链接: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. 【POJ】2954 Triangle(pick定理)

    http://poj.org/problem?id=2954 表示我交了20+次... 为什么呢?因为多组数据我是这样判断的:da=sum{a[i].x+a[i].y},然后!da就表示没有数据了QA ...

  2. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) ERROR 2013 (HY00 ...

  3. JAVA生成验证码

    <img border="0"                             src="ValidateCode"                ...

  4. Tomcat设置默认启动项目及Java Web工程设置默认启动页面

    Tomcat设置默认启动项目 Tomcat设置默认启动项目,顾名思义,就是让可以在浏览器的地址栏中输入ip:8080,就能访问到我们的项目.具体操作如下: 1.打开tomcat的安装根目录,找到Tom ...

  5. IIS浏览提示无法显示网页的解决方法

    1.错误号401.1 症状:HTTP 错误 401.1 - 未经授权:访问由于凭据无效被拒绝. 分析: 由于用户匿名访问使用的账号(默认是IUSR_机器名)被禁用,或者没有权限访问计算机,将造成用户无 ...

  6. javascript中的function

    function / 对象 所有的变量和方法名的:以字母,$ _开头其他随便,尽量使用英文字母命名,见名知意注意点:不允许使用关键字定义变量和方法的名称====函数即方法,方法即函数====百度:ja ...

  7. JSONP - 跨域AJAX

    基础概念 在进入本文正题之前,我们需要先了解一些基础概念(如果你已经对这些基础有所了解,可跳过此段落). 同源策略和跨域概念 同源策略(Same-orgin policy)限制了一个源(orgin)中 ...

  8. switch,break和default语句练习

    int w = 8; switch (w){ case 0: System.out.println("今天是星期日"); break; case 1: System.out.pri ...

  9. [GE]手动截取当前活动窗口,并且按规则命名(1/2)

    Function Take-ScreenShot { <# .SYNOPSIS Used to take a screenshot of the desktop or the active wi ...

  10. 【转】我们应该如何去了解JavaScript引擎的工作原理

    原文地址:http://www.nowamagic.net/librarys/veda/detail/1579 昨天收到一封来自深圳的一位前端童鞋的邮件,邮件内容如下(很抱歉,未经过他的允许,公开邮件 ...