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

题目传送门

题意:裸的对原点的极角排序,凸包貌似不行。

/************************************************
* Author        :Running_Time
* Created Time  :2015/11/3 星期二 14:46:47
* File Name     :POJ_2007.cpp
 ************************************************/

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos (-1.0);
int dcmp(double x)  {
    if (fabs (x) < EPS) return 0;
    else    return x < 0 ? -1 : 1;
}
struct Point   {
    double x, y;
    Point ()    {}
    Point (double x, double y) : x (x), y (y) {}
    Point operator - (const Point &r) const {       //向量减法
        return Point (x - r.x, y - r.y);
    }
    bool operator == (const Point &r) const {       //判断同一个点
        return dcmp (x - r.x) == 0 && dcmp (y - r.y) == 0;
    }
    bool operator < (const Point &r) const  {
        return x < r.x || (dcmp (x - r.x) == 0 && y < r.y);
    }
};
typedef Point Vector;
Point read_point(void)  {
    double x, y;
    scanf ("%lf%lf", &x, &y);
    return Point (x, y);
}
double polar_angle(Vector A)    {
    return atan2 (A.y, A.x);
}
double dot(Vector A, Vector B)  {
    return A.x * B.x + A.y * B.y;
}
double cross(Vector A, Vector B)    {
    return A.x * B.y - A.y * B.x;
}

bool cmp(Point a, Point b)  {
    return cross (a - Point (0, 0), b - Point (0, 0)) > 0;
}

int main(void)    {
    vector<Point> ps;
    double x, y;
    while (scanf ("%lf%lf", &x, &y) == 2)   {
        ps.push_back (Point (x, y));
    }
    sort (ps.begin ()+1, ps.end (), cmp);
    for (int i=0; i<ps.size (); ++i)    {
        printf ("(%.0f,%.0f)\n", ps[i].x, ps[i].y);
    }

   //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";

    return 0;
}

  

时间: 2024-11-29 03:19:23

简单几何(极角排序) POJ 2007 Scrambled Polygon的相关文章

poj 2007 Scrambled Polygon 极角排序

1 /** 2 极角排序输出,,, 3 主要atan2(y,x) 容易失精度,,用 4 bool cmp(point a,point b){ 5 if(cross(a-tmp,b-tmp)>0) 6 return 1; 7 if(cross(a-tmp,b-tmp)==0) 8 return length(a-tmp)<length(b-tmp); 9 return 0; 10 } 11 **/ 12 #include <iostream> 13 #include <algo

poj 2007 Scrambled Polygon(极角排序)

http://poj.org/problem?id=2007 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6701   Accepted: 3185 Description A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments ar

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

水题,根本不用凸包,就是一简单的极角排序. 叉乘<0,逆时针. #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> using namespace std; const int maxn=55; struct point { double x,y; } p[maxn]; double cross(poi

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

题目链接 题意 : 对输入的点极角排序 思路 : 极角排序方法 #include <iostream> #include <cmath> #include <stdio.h> #include <algorithm> using namespace std; struct point { double x,y; }p[50],pp; double cross(point a,point b,point c) { return (a.x-c.x)*(b.y-c

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 <std

POJ 2007 Scrambled Polygon(凸包)

Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7568   Accepted: 3604 Description A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments are called the

POJ 2007 Scrambled Polygon(计算几何 叉积排序啊)

题目链接:http://poj.org/problem?id=2007 Description A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments are called the vertices of the polygon. When one starts at any vertex of a close

POJ 2007 Scrambled Polygon

虽然A了但是完全不懂这题在干什么. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 105 using namespace std; struct point { int x,y; point (int x,int y):x(x),y(y) {} point () {} friend point operator - (point x

简单几何(线段相交) POJ 2653 Pick-up sticks

题目传送门 题意:就是小时候玩的一种游戏,问有多少线段盖在最上面 分析:简单线段相交,队列维护当前最上的线段 /************************************************ * Author :Running_Time * Created Time :2015/10/26 星期一 15:37:36 * File Name :POJ_2653.cpp ************************************************/ #inclu