UVA 218 - Moth Eradication 计算几何 凸包
来源:互联网 发布:淘宝客服的感想 编辑:程序博客网 时间:2024/06/03 19:38
凸包水题
求凸包 求边长
#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#define eps 1e-8using namespace std;struct Point{ double x,y; Point (double x = 0,double y = 0):x(x),y(y){}};typedef Point Vector;Vector operator -(Vector A,Vector B){ return Vector(A.x-B.x,A.y-B.y);}double Cross(Vector A, Vector B){ return A.x*B.y -A.y*B.x;}int cmp(Point a,Point b){ if(a.x<b.x)return 1; else if(a.x == b.x && a.y < b.y)return 1; return 0;}int ConvexHull(Point *s,int n,Point *ch){ sort(s,s+n,cmp); int m = 0; for(int i = 0; i < n; i++) { while(m >1 && Cross(ch[m-1]-ch[m-2],s[i]-ch[m-2])<= 0)m--; ch[m++] = s[i]; } int k = m; for(int i = n-2; i >=0; i--) { while(m > k && Cross(ch[m-1]-ch[m-2],s[i]-ch[m-2]) <= 0)m--; ch[m++] = s[i]; } if(n>1)m--; return m;}double Length(Point a,Point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}int main(){ #ifdef LOCAL freopen("in.txt","r",stdin); #endif // LOCAL int N; int T = 1; while(scanf("%d",&N) != EOF) { if(N == 0)break; struct Point s[N],t[N]; for(int i = 0; i < N; i++) scanf("%lf%lf",&s[i].x,&s[i].y); int m = ConvexHull(s,N,t); printf("Region #%d:\n",T++); for(int i = m; i >= 0 ;i--) { printf("(%.1lf,%.1lf)",t[i].x,t[i].y); if(i > 0)printf("-"); } printf("\n"); double dis = 0; for(int i = 0; i < m; i++) dis += Length(t[i],t[(i+1)%m]); printf("Perimeter length = %.2lf\n\n",dis); } return 0;}
- UVA 218 - Moth Eradication 计算几何 凸包
- UVA 218 Moth Eradication(凸包应用)
- UVA 218 Moth Eradication
- UVa 218 - Moth Eradication
- UVA 218 Moth Eradication【顺时针输出凸包顶点+凸包周长】
- uva218( Moth Eradication)
- UVA 10652 (计算几何 凸包)
- UVA 11168 (计算几何 凸包)
- UVA 10256 (计算几何 凸包)
- UVA 10652 - Board Wrapping 简单计算几何 凸包
- uva 10173 Smallest Bounding Rectangle (计算几何-凸包)
- uva 10652 Board Wrapping (计算几何-凸包)
- uva 10652 凸包 + 更新版计算几何模板
- 计算几何-凸包
- [计算几何]凸包算法
- 计算几何之凸包
- 计算几何-凸包问题
- 计算几何 --- 凸包 模板
- HDU 递推求解专题练习 2045 2046 2047 2048 2049 2050
- effective java中枚举的几种用法
- FFmpeg编译出错undefined reference to `img_convert’的解决方法
- OCP-1Z0-053-V12.02-236题
- 黑马程序员---Java基础学习笔记(多线程-前篇)
- UVA 218 - Moth Eradication 计算几何 凸包
- 给你写的launchpad430--TIMER--系列2
- 目标检测(Object Detection)原理与实现(三)
- jquery 缓存问题
- Android中“Connection to https://dl-ssl.google.com refused”问题
- 双向链表的基本操作
- 想对话框写文字
- Android 漫游之路------直接拿来用!最火的Android开源项目(终结)
- 在谷歌工作那些最糟糕的事情