题意:就是将所给点按凸包顺序输出,从原点开始。
分析:其实就是将除原点外的点进行极角排序。
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxn = 55;
int n,r;
struct Point
{
double x,y;
Point( double x = 0,double y = 0 ): x(x),y(y) { }
}point[maxn],ch[maxn];
double Cross( Point A,Point B,Point C )
{
return ( A.x - C.x ) * ( B.y - C.y ) - ( B.x - C.x ) * ( A.y - C.y );
}
bool cmp( Point A,Point B )
{
return Cross( A,B,point[0] ) >= 0;
}
int main()
{
n = 0;
while( scanf("%lf%lf",&point[n].x,&point[n].y) != EOF ){ n ++; }
sort( point+1,point+n,cmp );
for( int i = 0; i < n; i ++ )
printf("(%.0lf,%.0lf)\n",point[i].x,point[i].y);
return 0;
}