关闭

[POJ2007]Scrambled Polygon(计算几何)

232人阅读 评论(0) 收藏 举报
分类:

题目描述

传送门
题意:给出一个起点和一个凸多边形,要求从起点开始逆时针输出凸多边形的所有顶点

题解

很多人说是极角序,其实极角应该是向量(x,y)和x轴正方向的夹角,范围是[π,π]
我感觉直接极角排序不是很科学,因为起点不确定
所以直接利用叉积的性质来排序就可以了,也就是将所有点和起点求叉积

代码

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define N 105

const double eps=1e-9;
int dcmp(double x)
{
    if (x<=eps&&x>=-eps) return 0;
    return (x>0)?1:-1;
}
struct Vector
{
    double x,y;
    Vector(double X=0,double Y=0)
    {
        x=X,y=Y;
    }
};
typedef Vector Point;
Vector operator - (Vector A,Vector B) {return Vector(A.x-B.x,A.y-B.y);}

int n;
double x,y;
Point s,p[N];

double Cross(Vector A,Vector B)
{
    return A.x*B.y-A.y*B.x;
}
int cmp(Point a,Point b)
{
    return Cross(a-s,b-s)>0;
}
int main()
{
    scanf("%lf%lf",&x,&y);s=Point(x,y);
    while (~scanf("%lf%lf",&x,&y))
        p[++n]=Point(x,y);
    sort(p+1,p+n+1,cmp);
    printf("(%.0lf,%.0lf)\n",s.x,s.y);
    for (int i=1;i<=n;++i)
        printf("(%.0lf,%.0lf)\n",p[i].x,p[i].y);
}
0
0
查看评论

POJ2007Scrambled Polygon

Language: Default Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7629   Accepted: ...
  • R1986799047
  • R1986799047
  • 2015-09-06 18:15
  • 625

poj2007——Scrambled Polygon

<br />对各个点进行极角排序,然后输出,搞定!<br />#include<stdio.h> #include<math.h> #include<string.h> #define max 55 struct node { ...
  • k1246195917
  • k1246195917
  • 2010-09-12 13:05
  • 356

poj2007 Scrambled Polygon【极角排序】

题目链接:http://poj.org/problem?id=2007 题意:好像就是给你个凸包,然后输出极角排序后的结果 解析:极角排个序就好?#include <iostream> #include <cstdio> #include <cstring> ...
  • Richie_ll
  • Richie_ll
  • 2017-04-18 17:18
  • 267

ACM-计算几何之Scrambled Polygon——poj2007

ACM 计算几何 Scrambled Polygon poj2007 几种极角排序
  • lx417147512
  • lx417147512
  • 2014-04-27 20:15
  • 1559

POJ2007 Scrambled Polygon

POJ2007  Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8198 Accepted: 3891 Description A closed polygon is a figur...
  • zhulf0804
  • zhulf0804
  • 2016-07-27 21:09
  • 267

POJ2007 Scrambled Polygon

极角排序
  • wangwenhao00
  • wangwenhao00
  • 2014-04-27 10:00
  • 721

poj2007 Scrambled Polygon (叉积极角排序)

题目链接: http://poj.org/problem?id=2007 Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissi...
  • sinat_30126425
  • sinat_30126425
  • 2015-10-09 20:25
  • 183

POJ-2007 Scrambled Polygon(计算几何)

Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8217   Accepted: 3903 ...
  • huatian5
  • huatian5
  • 2016-07-28 20:47
  • 197

POJ2007 Scrambled Polygon 凸多边形顶点输出

Description A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments are called th...
  • Megumin
  • Megumin
  • 2016-07-27 20:14
  • 120

Scrambled Polygon(poj2007极角排序输出凸包)

题意:给你一些点,让你按照极角的顺序输出凸包的顶点 思路:直接按照向量排序 按照向量叉乘的正负判断点所在的位置,类似于卷包裹的凸包,每次按照一条边排序,选择最外面的一条边,再按照选择的边在排序,再选直到点重合位置 这道题直接按照(0,0)点极角排序,如果极角相同选择最近的那个因为在一条直线上先...
  • leonharetd
  • leonharetd
  • 2013-10-08 19:21
  • 414
    个人资料
    • 访问:642769次
    • 积分:17904
    • 等级:
    • 排名:第630名
    • 原创:1151篇
    • 转载:7篇
    • 译文:0篇
    • 评论:190条
    联系方式
    QQ:1209628538 加好友请备注省份和ID
    E-mail:fiona_2000@126.com
    最新评论