HDU ACM 1392 Surround the Trees->凸包
来源:互联网 发布:淘宝店推广软文 编辑:程序博客网 时间:2024/06/10 14:00
分析:直接求出凸包,再算边长即可。另外只有一个点时为0.00单独处理,两个点直接为距离也单独处理。
#include<iostream>#include<cmath>#include<algorithm>using namespace std;struct Point{Point(){}Point(double _x,double _y):x(_x),y(_y){}Point operator-(const Point& a) const{return Point(x-a.x,y-a.y);}double x,y;};double dis(const Point& a,const Point& b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}double cross(const Point& a,const Point& b){return a.x*b.y-a.y*b.x;}bool cmp(const Point& a,const Point& b){if(a.x!=b.x)return a.x<b.x;elsereturn a.y<b.y;}int convexhull(Point* p,int n,Point* ch){int i,m,k;sort(p,p+n,cmp);m=0;for(i=0;i<n;i++) //上凸包{while(m>1 && cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;ch[m++]=p[i];}k=m;for(i=n-2;i>=0;i--) //下凸包{while(m>k && cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;ch[m++]=p[i];}if(n>1) m--;return m;}int main(){Point a[105],p[105];int n,i,m;double ans;while(scanf("%d",&n)==1 &&n){for(i=0;i<n;i++)scanf("%lf%lf",&a[i].x,&a[i].y);if(n==1)printf("0.00\n");else if(n==2){printf("%.2lf\n",dis(a[0],a[1]));}else{m=convexhull(a,n,p);ans=0;for(i=1;i<=m;i++)ans+=dis(p[i],p[i-1]);printf("%.2lf\n",ans);}}return 0;}
0 0
- HDU ACM 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(凸包模板)
- 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(凸包周长)
- org.tinygroup.xmlparser-XML解析器
- 【Java】【Flume】Flume-NG启动过程源码分析(一)
- phprpc 使用实例
- 在MyEclipse下创建Java Web项目 入门(图文并茂)经典教程
- Google面试题-高楼扔鸡蛋问题
- HDU ACM 1392 Surround the Trees->凸包
- 2015年移动金融应用行业报告
- 歪解Activity生命周期-----初学者彻底理解指南
- Leetcode[1]-Two Sum
- org.tinygroup.htmlparser-Html解析器
- 二分查找
- oracle 数据库 表空间创建 用户创建 用户授权
- org.tinygroup.application-应用启动框架
- Mybatis学习(6)动态sql语句