POJ - 2007 Scrambled Polygon (凸包)

版权声明:沃斯里德小浩浩啊 https://blog.csdn.net/Healer66/article/details/83689525

链接:

http://poj.org/problem?id=2007

题意:

逆时针输出凸多边形的点.

思路:

排序,按叉乘排

代码:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
struct point
{
    int x,y;
}p[55];
int cmp(point a,point b,point c)
{
    return (c.x-a.x)*(b.y-a.y) - (c.y - a.y) * (b.x - a.x);
}
bool cmp1(point a,point b)
{
    return cmp(p[0],a,b) < 0;
}
int main()
{
    int  n = 0;
    while(cin>>p[n].x>>p[n].y) n++;
    sort(p+1,p+n,cmp1);
    for(int i = 0; i < n;i++)
    {
        printf("(%d,%d)\n",p[i].x,p[i].y);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Healer66/article/details/83689525