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