首页 > 其他 > 详细

Scrambled Polygon

时间:2020-10-08 22:26:05      阅读:47      评论:0      收藏:0      [点我收藏+]

题目链接: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);
}

 

Scrambled Polygon

原文:https://www.cnblogs.com/zcb123456789/p/13782482.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!