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;
}
就是把点逆时针顺序排序
把每个点看成从原点出发的向量
利用叉积逆时针转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;
}
相关文章推荐
- POJ 2007 Scrambled Polygon(极角排序)
- POJ 2007 Scrambled Polygon 凸包点排序逆时针输出
- POJ 2007 Scrambled Polygon
- POJ 2007 Scrambled Polygon (凸包输出点路径)
- poj 2007 Scrambled Polygon
- POJ 2007 Scrambled Polygon 极角排序
- POJ 2007 Scrambled Polygon(几何)
- poj 2007 Scrambled Polygon [极角排序]
- POJ 2007 Scrambled Polygon 极角排序
- POJ 2007 Scrambled Polygon(点的极角排序)
- POJ 2007 Scrambled Polygon(极角排序)
- poj 2007 Scrambled Polygon 【极角排序】
- poj 2007 Scrambled Polygon(计算几何)
- POJ 2007 Scrambled Polygon 凸包点排序逆时针输出
- POJ 2007 Scrambled Polygon(凸包)
- POJ 2007 Scrambled Polygon 凸包
- poj--2007--Scrambled Polygon(数学几何基础)
- POJ 2007 Scrambled Polygon (极角排序)
- POJ 2007 Scrambled Polygon(凸包)
- poj 2007 Scrambled Polygon(凸多边形顶点输出)