题目意思,给了你一个凸包,给定起点(0,0),要你按从小到大的极角序输出其他点,极角是以原点为起点的。
凸包可解。直接把Scan算法那个排序部分拿过来就好了。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<utility>
#include<string>
#include<set>
#include<vector>
#include<stack>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<cmath>
using namespace std;
const double eps=1e-8;
const int M=70;
struct point
{
int x,y;
}points[M];
int n;
double dis(point a,point b)
{
return sqrt((double)((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)));
}
double cross(point p0,point p1,point p2)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
bool cmp(point p,point q)
{
double k=cross(points[0],p,q);
if(k<-eps)
return 0;
else if(fabs(k)<eps && (dis(p,points[0])-dis(q,points[0]))>eps)
return 0;
else
return 1;
}
int main()
{
n=0;
while(scanf("%d %d",&points[n].x,&points[n].y)==2) n++;
sort(points+1,points+n,cmp);
for(int i=0;i<n;i++)
printf("(%d,%d)\n",points[i].x,points[i].y);
system("pause");
return 0;
}