题目地址
就是把点逆时针顺序排序
把每个点看成从原点出发的向量
利用叉积逆时针转180°以内为正的性质就能逆时针将点排序了
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
typedef pair<int,int> Point;
vector<Point> G;
double operator ^ (const Point& x,const Point& y){ //叉积 return x.first*y.second-x.second*y.first;
}
bool cmp(const Point& x,const Point& y){return (x^y) > 0;
}
int main()
{int x,y;while(scanf("%d%d",&x,&y)!=EOF){G.push_back(Point(x,y));}sort(G.begin()+1,G.end(),cmp);for(int i=0;i<G.size();i++){printf("(%d,%d)\n",G[i].first,G[i].second);}return 0;}