Scrambled Polygon

题目链接:https://vjudge.net/problem/POJ-2007

题意:给你一个凸多边形的点,然后再按照极角排序输出那些点。

思路:直接用差积极角排序。

#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4.;
const int maxn=200005;
struct point
{
    int x,y;
    point friend operator -(point A,point B)
    {
        return {A.x-B.x,A.y-B.y};
    }
};
point p[205];
int chaj(point A,point B)
{
    return A.x*B.y-A.y*B.x;
}
bool cmp(point A,point B)
{
    return chaj(A-p[1],B-p[1])>0;
}
int main()
{
    int n=1;
    while(~scanf("%d%d",&p[n].x,&p[n].y))
        n++;
    n--;
    sort(p+2,p+n+1,cmp);
    for(int i=1;i<=n;i++)
        printf("(%d,%d)\n",p[i].x,p[i].y);
}

 

posted @ 2020-10-08 19:59  ~zcb  阅读(117)  评论(0编辑  收藏  举报