题目扯了那么多,又是算斜率, 又是不同象限的,最后就是一个极角排序
注意,这里的极角排序是一般grahm-scan算法的逆序即可
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
const int maxn=55;
const double eps=1e-8;
using namespace std;
int sgn(double x){
if(fabs(x)<eps)
return 0;
if(x>0)
return 1;
if(x<0)
return -1;
}
struct point{
double x,y;
//double slope=0;
point(){}
point(double _x,double _y){
x=_x;
y=_y;
}
};
typedef point vector;
vector operator - (vector a,vector b){
return point(a.x-b.x,a.y-b.y);
}
double operator * (vector a,vector b){
return a.x*b.x+a.y*b.y;
}
double operator ^ (vector a,vector b){
return a.x*b.y-a.y*b.x;
}
bool operator < (vector a,vector b){
if(a.x==b.x &&a.y<b.y ||a.x<b.x)
return true;
return false;
}
double dis(point a,point b){
return hypot(a.x-b.x,a.y-b.y);
}
struct convex{
int n;
point p[maxn];
};
point p[maxn];
bool cmp(point a,point b){
int d=sgn((a-p[0])^(b-p[0]));
if(d<0 || d==0 && sgn(dis(a,p[0])-dis(b,p[0]))<0 )//d<0 逆序
return true;
return false;
}
int main(){
//freopen("input.txt","r",stdin);
int i=0;
while(~scanf("%lf%lf",&p[i].x,&p[i].y))
i++;
sort(p,p+i,cmp);
printf("(%d,%d)\n",int(p[0].x),int(p[0].y));
for(int j=i-1;j>0;j--)
printf("(%d,%d)\n",int(p[j].x),int(p[j].y));
}