给你坐标的点只有三个象限,
并且第一个点就是原点,为起始点,
让你把这些凸包的点排序,逆时针输出,
就是用叉积排序就好了,一个sort搞定。
一开始没看懂题目。。看别人题解的翻译才懂的。。
读题真的伤的,明明很水的题目。
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
struct pnode{
int x,y;
pnode (int xx=0,int yy=0):x(xx),y(yy){}
pnode operator - (const pnode &b)const{
return pnode(x-b.x,y-b.y);
}
int operator ^ (const pnode&b)const{
return x*b.y-y*b.x;
}
};
pnode p[55],p0;
bool cmp(pnode a,pnode b)
{
return ((a-p0)^(b-p0))>0;
}
int main()
{
int a,b;
int id = 0;
while( scanf("%d %d",&a,&b)==2)
{
p[id].x = a;
p[id++].y = b;
}
p0.x = p[0].x;
p0.y = p[0].y;
sort(p+1,p+id,cmp);
for( int i = 0 ; i <id;++i)
{
printf("(%d,%d)\n",p[i].x,p[i].y);
}
return 0;
}