POJ 2007 Scrambled Polygon 极角序 水

Posted ( m Lweleth)

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ 2007 Scrambled Polygon 极角序 水相关的知识,希望对你有一定的参考价值。

LINK

题意:给出一个简单多边形,按极角序输出其坐标。

思路:水题。对任意两点求叉积正负判断相对位置,为0则按长度排序

 

/** @Date    : 2017-07-13 16:46:17
  * @FileName: POJ 2007 凸包极角序.cpp
  * @Platform: Windows
  * @Author  : Lweleth ([email protected])
  * @Link    : https://github.com/
  * @Version : $Id$
  */
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
//#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;

struct point
{
	int x, y;
	point(){}
	point(int _x, int _y){x = _x, y = _y;}
	point operator -(const point &b) const
	{
		return point(x - b.x, y - b.y);
	}
	int operator *(const point &b) const 
	{
		return x * b.x + y * b.y;
	}
	int operator ^(const point &b) const
	{
		return x * b.y - y * b.x;
	}
};

double xmult(point p1, point p2, point p0)  
{  
    return (p1 - p0) ^ (p2 - p0);  
}  

double distc(point a, point b)
{
	return sqrt((double)((b - a) * (b - a)));
}

point p[N];

int cmp(point a, point b)
{
	int t = xmult(a, b, p[0]);
	if(t == 0)
		return distc(a, p[0]) < distc(b, p[0]);
	else 
		return t > 0;

}

int main()
{
	int x, y;
	int cnt = 0;
	while(~scanf("%d%d", &x, &y))
	{
		p[cnt++] = point(x, y);
		sort(p + 1, p + cnt, cmp);
	}
	for(int i = 0; i < cnt; i++)
		printf("(%d,%d)\n", p[i].x, p[i].y);

    return 0;
}

以上是关于POJ 2007 Scrambled Polygon 极角序 水的主要内容,如果未能解决你的问题,请参考以下文章

POJ 2007 Scrambled Polygon 极角序 水

POJ 2007 Scrambled Polygon

[POJ2007]Scrambled Polygon(计算几何 极角排序)

POJ 2007 Scrambled Polygon(极角排序)

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

Scrambled Polygon---poj2007(利用叉积排序)