题目链接
题目大意:给你凸包上的点集,从原点开始逆时针输出点。
一开始用atan2排序,但莫名其妙wa掉了,可能精度不够把。。然后改成叉积才a掉。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const double eps=1e-8;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=5e5+10;
int sgn(double x)
{
if(fabs(x)<eps) return 0;
return x>0?1:-1;
}
struct Point
{
double x,y;
Point(double x=0,double y=0):x(x),y(y){
}
Point operator - (Point a){
return Point(x-a.x,y-a.y);}
};
double cross(Point a,Point b)
{
return a.x*b.y-a.y*b.x;
}
Point p[N];
bool cmp(Point a,Point b)//按叉积排序
{
return cross(a,b)>0;
}
int main()
{
int n=0;
double x,y;
scanf("%lf%lf",&x,&y);
while(scanf("%lf%lf",&p[n].x,&p[n].y)==2){
n++;
}
sort(p,p+n,cmp);
printf("(0,0)\n");
for(int i=0;i<n;i++){
printf("(%.0f,%.0f)\n",p[i].x,p[i].y);
}
return 0;
}