首页 > 代码库 > POJ 2007 Scrambled Polygon 极角序 水
POJ 2007 Scrambled Polygon 极角序 水
LINK
题意:给出一个简单多边形,按极角序输出其坐标。
思路:水题。对任意两点求叉积正负判断相对位置,为0则按长度排序
/** @Date : 2017-07-13 16:46:17 * @FileName: POJ 2007 凸包极角序.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @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 极角序 水
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。