POJ2007--Scrambled Polygon
2015-08-16 21:22
579 查看
题目大意:乱序给出凸多边形的顶点坐标,要求按逆时针顺序输出各顶点。给的第一个点一定是(0,0),没有其他点在坐标轴上,没有三点共线的情况。
分析:利用叉积排序。
代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
struct P {
int x, y;
P(){}
P(int x, int y):x(x), y(y) {}
};
P operator -(P p, P q) {
return P(p.x-q.x, p.y-q.y);
}
int operator ^(P p, P q) {
return p.x*q.y-p.y*q.x;
}
bool operator <(P p, P q) {<span style="white-space:pre"> //如果p1^p2 〉0,说明p1经逆时针旋转<180度可以到p2,则 p1 </span><<span style="white-space:pre"> p2</span>
if(((p-P(0, 0))^(q-P(0, 0))) < 0)
return false;
else return true;
}
P ps[60];
int main() {
int n = 0;
while(~scanf("%d%d", &ps
.x, &ps
.y)) {
n++;
}
sort(ps+1, ps+n);
for(int i = 0; i < n; i++)
printf("(%d,%d)\n", ps[i].x, ps[i].y);
return 0;
}
分析:利用叉积排序。
代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
struct P {
int x, y;
P(){}
P(int x, int y):x(x), y(y) {}
};
P operator -(P p, P q) {
return P(p.x-q.x, p.y-q.y);
}
int operator ^(P p, P q) {
return p.x*q.y-p.y*q.x;
}
bool operator <(P p, P q) {<span style="white-space:pre"> //如果p1^p2 〉0,说明p1经逆时针旋转<180度可以到p2,则 p1 </span><<span style="white-space:pre"> p2</span>
if(((p-P(0, 0))^(q-P(0, 0))) < 0)
return false;
else return true;
}
P ps[60];
int main() {
int n = 0;
while(~scanf("%d%d", &ps
.x, &ps
.y)) {
n++;
}
sort(ps+1, ps+n);
for(int i = 0; i < n; i++)
printf("(%d,%d)\n", ps[i].x, ps[i].y);
return 0;
}
相关文章推荐
- hdu 4983 Goffi and GCD(欧拉函数)
- Beanstalkd的使用(Golang)
- NYOJ 635 Oh, my goddess (简单BFS)
- Django(中)
- POJ 2195 D - Going Home 费用流
- GoAgent下local文件下proxy.ini文件各项参数介绍
- 如何直接从 Google Play 下载 APK 文件?
- 如何用Go语言打造一个高性能MySQL Proxy
- [Machine Learning & Algorithm] 决策树与迭代决策树(GBDT)
- 如何用Go语言打造一个高性能MySQL Proxy
- Google APAC 2016 University Graduates Test Practice Round APAC test
- django-rest-framework指南(3):Class Based Views(类视图)
- Google APAC 2016 University Graduates Test(google校招笔试)
- Google笔试(2015年8月)
- Codeforces Round #313 (Div. 2)-Gerald's Hexagon 找规律-几何规律-
- HDU_1847 Good Luck in CET-4 Everybody!(SG函数)
- hdu 3699 Aragorn's Story(树链剖分)
- GoldenGate 使用reperror进行错误处理
- Leetcode问题-1(Two Sum)
- win10 google浏览器设置