您的位置:首页 > 编程语言 > Go语言

POJ 2007 Scrambled Polygon .

2016-07-29 08:43 465 查看
题目地址

就是把点逆时针顺序排序

把每个点看成从原点出发的向量

利用叉积逆时针转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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: