UVa 681 - Convex Hull Finding
来源:互联网 发布:泰牛 2017 php 编辑:程序博客网 时间:2024/05/29 04:10
题目:给你一个多边形,输出凸包上的点,从左下开始、逆时针方向。
分析:计算几何、凸包。赤果果的凸包,直接算出没有多余点的凸包即可(删除不是拐点的点)。
注意:输出格式,WA了n次菜发现、n被printf了。
#include <algorithm>#include <iostream>#include <cstdlib> #include <cstring>#include <cstdio>#include <cmath>using namespace std;typedef struct pnode{int x,y,d;}point;point P[600];//两点间距离 int dist( point a, point b ){return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}//叉乘 ab*ac int crossproduct( point a, point b, point c ){return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);}//坐标排序 bool cmp1( point a, point b ){return a.y==b.y?a.x<b.x:a.y<b.y;}//级角排序 bool cmp2( point a, point b ){double cp = crossproduct( P[0], a, b );if ( !cp ) return a.d < b.d;else return cp > 0;}void Graham( int n ){sort( P+0, P+n, cmp1 );for ( int i = 1 ; i < n ; ++ i )P[i].d = dist( P[0], P[i] );sort( P+1, P+n, cmp2 );//计算凸包 int top = 1;for ( int i = 2 ; i < n ; ++ i ) {while ( top > 0 && crossproduct( P[top-1], P[top], P[i] ) <= 0 ) -- top;P[++ top] = P[i];}//删点 P[++ top] = P[0];int now = 1;for ( int i = 2 ; i <= top ; ++ i )if ( !crossproduct( P[now-1], P[now], P[i] ) ) P[now] = P[i];else P[++ now] = P[i];if ( now < 2 ) {printf("0\n");return;}printf("%d\n",now+1);for ( int i = 0 ; i <= now ; ++ i )printf("%d %d\n",P[i].x,P[i].y);}int main(){int t,n,m;while ( scanf("%d",&t) != EOF ) {printf("%d\n",t);while ( t -- ) {scanf("%d",&n);for ( int i = 0 ; i < n ; ++ i )scanf("%d%d",&P[i].x,&P[i].y);if (t) scanf("%d",&m);Graham( n );if (t) printf("-1\n");}}}
- UVa 681 - Convex Hull Finding
- uva 681 Convex Hull Finding
- UVa 681 Convex Hull Finding (凸包,Graham‘s Scan)
- UVA 681 Convex Hull Finding【逆时针输出凸包顶点】
- UVA, 681Convex Hull Finding(凸包)
- Uva - Convex Hull Finding - 凸包裸题 共线处理
- UVA 11626 Convex Hull
- UVa 11626 - Convex Hull
- 凸包问题Finding the convex hull
- convex hull
- Convex Hull
- convex hull
- UVA 11626 Convex Hull(凸包:模板题)
- Convex hull: Graham scan
- HDU4697 Convex hull
- poj 3405 Convex hull
- ZOJ 3871 Convex Hull
- Convex hull trick算法
- iframe只显示竖的滚动条
- 平衡二叉树的数组表示算法
- Android中通过Intent 调用图片、视频、音频、录音、拍照
- 优秀程序员不得不知道的20个位运算技巧
- MATLAB如何输出无白边图片的操作方法
- UVa 681 - Convex Hull Finding
- register解析
- 改良编程的技巧
- eclipse下tomcat出现did not find a matching property.
- register解析
- 如何自学python
- 测试编译器性能的源码
- Android学习笔记之AndroidManifest.xml文件解析
- Linux的一些快捷键