hdu_1392 Surround the Trees(凸包)
来源:互联网 发布:js除于10等于整数 编辑:程序博客网 时间:2024/06/06 21:38
http://acm.hdu.edu.cn/showproblem.php?pid=1392
分析: 用了凸包模板很快就可以出来(注意特殊情况的处理,前两次就是这么WA的)
代码:
//hdu 1392#include <cstdio>#include <cstring>#include <cmath>#include <queue>#include <iostream>#include <algorithm>using namespace std;#define MAXN 110const double pi=acos(-1.0);struct Point{ double x,y; Point(){} Point(double _x,double _y) { x = _x; y = _y; } Point operator - (const Point &b)const { return Point(x-b.x,y-b.y); } double operator *(const Point &b)const { return x*b.x+y*b.y; }}e[MAXN],res[MAXN];int cmp(Point a,Point b){ return a.x != b.x ? a.x<b.x : a.y<b.y;}double cross(Point a,Point b,Point c)//向量积{ return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);}double dist(Point a,Point b){ return sqrt((a-b)*(a-b));}int convex(int n)//求凸包上的点{ sort(e,e+n,cmp); int m=0,k; for(int i=0;i<n;i++){ while(m>1&&cross(res[m-1],e[i],res[m-2])<=0)m--; res[m++]=e[i]; } k=m; for(int i=n-2;i>=0;i--){ while(m>k&&cross(res[m-1],e[i],res[m-2])<=0)m--; res[m++]=e[i]; } if(n>1) m--; return m;}int main(){ freopen("in.txt","r",stdin); int n,m; double ans; while(scanf("%d",&n)!=EOF){ if(n==0) break; ans=0; for(int i=0;i<n;i++) scanf("%lf%lf",&e[i].x,&e[i].y); if(n==1) {printf("0.00\n"); continue;} if(n==2) {printf("%.2lf\n",dist(e[0],e[1]));continue;} m=convex(n); for(int i=1;i<m;i++) ans+=dist(res[i],res[i-1]); ans+=dist(res[m-1],res[0]); printf("%.2lf\n",ans); } return 0;}
0 0
- hdu_1392 Surround the Trees(凸包)
- Surround the Trees&&凸包入门题
- HDU1392--Surround the Trees--凸包
- HDU 1392 Surround the Trees(凸包)
- HDUJ 1392 Surround the Trees 凸包
- HDOJ_1392 Surround The Trees (凸包模版)
- 凸包问题 hdu1392 Surround the Trees
- HDU1392 Surround the Trees 简单凸包
- HDOJ 1392 Surround the Trees (凸包)
- ZJU 1453 Surround the Trees 凸包
- hdu-1392 Surround the Trees(凸包)
- HDU 1392 Surround the Trees(凸包)
- 凸包模版 HDU1392 Surround the Trees
- hdu 1392 Surround the Trees 凸包
- hdu 1392 Surround the Trees【凸包】
- 【凸包】HDU1392 Surround the Trees
- HDU1392 Surround the Trees(凸包)
- hdu1392 Surround the Trees 凸包
- 常用开源软件maven坐标
- [转]怎样在UICollectionView中添加Header和footer
- 第7周作业-for循环判断
- 存储过程与游标的配合使用
- LNMP
- hdu_1392 Surround the Trees(凸包)
- windows下配置java串口开发/运行环境详细
- 当当网:一家早就该卖掉的非主流电商
- 摇一摇截屏相关功能 -- 集成文档
- Java中使用JDBC操作MySQL数据库
- Spring简单的annotaction
- Matlab中将矩阵数据转换成txt文件保存输出的办法
- [linux命令] cal 日历,cat连接并显示文件
- 循环大战