poj_2007_Scrambled Polygon
2013-11-04 20:43
148 查看
题型:计算几何
题意:给出符合凸包的若干的点,第一个输入的点保证是原点,将这些点从原点开始按逆时针顺序输出。
分析:
题目中说没有在x轴上和y轴上的点(除了原点),所以极角排序排序的时候,将原点除外之后再排序,否则将得到错误答案(被坑死了,一排WA。。。)
由于木有说一共输入多少个点,所以用!=EOF处理,用文件输入输出来检测数据。
代码:
题意:给出符合凸包的若干的点,第一个输入的点保证是原点,将这些点从原点开始按逆时针顺序输出。
分析:
题目中说没有在x轴上和y轴上的点(除了原点),所以极角排序排序的时候,将原点除外之后再排序,否则将得到错误答案(被坑死了,一排WA。。。)
由于木有说一共输入多少个点,所以用!=EOF处理,用文件输入输出来检测数据。
代码:
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #define eps 1e-10 using namespace std; struct point { double x,y; } p[100]; //极角排序 double cross(const point &p1, const point &p2, const point &q1, const point &q2) { return (q2.y - q1.y)*(p2.x - p1.x) - (q2.x - q1.x)*(p2.y - p1.y); } bool cmp(const point &a, const point &b) { point origin; origin.x = origin.y = 0; return cross(origin,b,origin,a) < 0; } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n=0; while(~scanf("%lf%lf",&p .x,&p .y)) { n++; } sort(p+1,p+n,cmp); for (int i=0; i<n; i++) { printf("(%.0lf,%.0lf)\n",p[i].x,p[i].y); } return 0; }
相关文章推荐
- poj--2007--Scrambled Polygon(数学几何基础)
- poj 2007 Scrambled Polygon [极角排序]
- poj 2007 Scrambled Polygon 凸包点排序逆时针输出
- POJ 2007 Scrambled Polygon [凸包 极角排序]
- POJ 3573 I18n (字符串乱搞)Northeastern Europe 2007
- POJ 2007 Scrambled Polygon
- POJ 2007 极角排序
- BZOJ 1066 POJ 2711 [SCOI2007]蜥蜴
- poj--2007--Scrambled Polygon(数学几何基础)
- poj 2007 Scrambled Polygon(凸包Graham扫描线模板)
- POJ 2007 Scrambled Polygon 凸包点排序逆时针输出
- POJ 2007 计算几何水题
- POJ 2007 Scrambled Polygon 凸包加排序 水题一道
- poj 2007 Scrambled Polygon
- EOJ 1918/POJ 3444/Rocky Mountain 2007 Wavelet Compression
- POJ--2007(计算几何之极角排序)
- POJ 2007 Scrambled Polygon
- POJ 2007 Scrambled Polygon
- poj2007——Scrambled Polygon
- poj1698 [ Usaco2007 Feb ] --最大流