HDU 1392 Surround the Trees(凸包)
来源:互联网 发布:solus linux 编辑:程序博客网 时间:2024/06/05 08:53
【题意】给n个点求凸包。
【分析】求凸模板,这里注意特判n==2的情况,没注意到WA一回!
【AC代码】
#include <set>#include <map>#include <math.h>#include <vector>#include <stdio.h>#include <iostream>#include <algorithm>using namespace std;const int maxn = 10010;const double PI = acos(-1);struct Point{ double x,y; Point(){} Point(int x,int y):x(x),y(y){} bool operator<(const Point &rhs)const{ if(x==rhs.x) return y<rhs.y; return x<rhs.x; }}q[maxn],p[maxn];double Cross(const Point &a,const Point &b){ return a.x*b.y-a.y*b.x;}double get_Dis(const Point &a,const Point &b){ return (double)sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}int main(){ int n; while(scanf("%d",&n)!=EOF){ if(n==0) return 0; for(int i=0; i<n; i++) scanf("%lf%lf",&q[i].x,&q[i].y); sort(q,q+n); if(n==1){printf("0.00\n");continue;}if(n==2){printf("%.2lf\n",get_Dis(q[0],q[1]));continue;} int m = 0; for(int i=0; i<n; i++){//"下凸包" while(m>1&&Cross(Point(p[m-1].x-p[m-2].x,p[m-1].y-p[m-2].y),Point(q[i].x-p[m-2].x,q[i].y-p[m-2].y))<=0) m--; p[m++] = q[i]; } int k = m; for(int i=n-2; i>=0; i--){//"上凸包" while(m>k&&Cross(Point(p[m-1].x-p[m-2].x,p[m-1].y-p[m-2].y),Point(q[i].x-p[m-2].x,q[i].y-p[m-2].y))<=0) m--; p[m++] = q[i]; } if(n>1) m--; double sum = 0; for(int i=0,j=1; i<m; i++,j++){ sum += get_Dis(p[i],p[j]); } printf("%.2f\n",sum); } return 0;}
0 0
- HDU 1392 Surround the Trees(凸包)
- hdu-1392 Surround the Trees(凸包)
- HDU 1392 Surround the Trees(凸包)
- hdu 1392 Surround the Trees 凸包
- hdu 1392 Surround the Trees【凸包】
- hdu 1392 Surround the Trees(凸包模板)
- ZJU 1453(hdu 1392) Surround the Trees(凸包)
- hdu 1392 Surround the Trees(凸包模版)
- hdu 1392 Surround the Trees 基础 二维凸包 算法
- hdu 1392 Surround the Trees 凸包模板题
- HDU 1392 Surround the Trees 构造凸包
- HDU 1392 Surround the Trees【凸包周长】
- hdu 1392 Surround the Trees(凸包模板题)
- hdu 1392 Surround the Trees(凸包)
- HDU-#1392 Surround the Trees(Graham & Andrew +凸包)
- HDU 1392 Surround the Trees 凸包的周长
- HDU 1392 Surround the Trees(凸包周长)
- hdu 1392 Surround the Trees( 凸包问题)
- Unityads安卓接入
- Closest Common Ancestors【POJ1470】——LCA
- 好的个人网站收藏
- [Modern OpenGL系列(四)]在OpenGL中使用Shader
- 最短路水题 HDU 1874畅通工程续
- HDU 1392 Surround the Trees(凸包)
- DFS系列 POJ(自认为的讲解)
- JVM学习笔记(一)------基本结构
- python中FutureWarning问题解决方法
- Genuino 101无法下载程序的问题
- [Java]常见算法问题(持续学习,更新)
- AndroidStudio默认快捷键
- 01背包水题 HDU 2546饭卡
- 介绍LEDE工程-openwrt社区讨论2