HDU ACM 1392 Surround the Trees->凸包
分析:直接求出凸包。再算边长就可以。
另外仅仅有一个点时为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;
else
return 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;
}
HDU ACM 1392 Surround the Trees->凸包的更多相关文章
- HDU 1392 Surround the Trees(凸包入门)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 题解报告:hdu 1392 Surround the Trees(凸包入门)
Problem Description There are a lot of trees in an area. A peasant wants to buy a rope to surround a ...
- HDU 1392 Surround the Trees(凸包)
题面 懒得粘贴了... 大致题意:坐标系内有若干个点,问把这些点都圈起来的最小凸包周长. 题解 直接求出凸包,统计一遍答案即可 #include<iostream> #include< ...
- HDU 1392 Surround the Trees(凸包)题解
题意:给一堆二维的点,问你最少用多少距离能把这些点都围起来 思路: 凸包: 我们先找到所有点中最左下角的点p1,这个点绝对在凸包上.接下来对剩余点按照相对p1的角度升序排序,角度一样按距离升序排序.因 ...
- HDU 1392 Surround the Trees 构造凸包
又是一道模板题 #include <iostream> #include <cstring> #include <cstdlib> #include <cst ...
- HDU - 1392 Surround the Trees (凸包)
Surround the Trees:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...
- hdu 1392 Surround the Trees 凸包模板
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1392:Surround the Trees(计算几何,求凸包周长)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1392 Surround the Trees (凸包)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- adb logcat 查看日志
使用 logcat 命令 查看和跟踪系统日志缓冲区的命令logcat的一般用法是: [adb] logcat [<option>] ... [<filter-spec>] .. ...
- Ubuntu 14.04安装Chromium浏览器并添加Flash插件Pepper Flas
转自Ubuntu 14.04安装Chromium浏览器并添加Flash插件Pepper Flash Player Chromium谷歌的开源浏览器将不再支持Netscape浏览器插件API,Adobe ...
- EMMC 简要介绍
一直想写一篇关于EMMC的文章,但是因为之前弄了很多PPT,所以一直提不起兴趣,索性直接把之前的一个介绍EMMC的PPT贴出来给大家看看,有什么问题可以直接跟帖,我会第一时间进行解答,谢谢
- Linux守护进程daemon
守护进程,也就是通常说的Daemon进程,是Linux中的后台服务进程.它是一个生存期较长的进程,通常独立于控制终端并且周期性地执行某种任务或等待处理某些发生的事件.守护进程常常在系统引导装入时启 ...
- Deep Learning论文笔记之(八)Deep Learning最新综述
Deep Learning论文笔记之(八)Deep Learning最新综述 zouxy09@qq.com http://blog.csdn.net/zouxy09 自己平时看了一些论文,但老感觉看完 ...
- Linux修改文件时候出现崩溃,产生了一个.swap交换文件,如何修复?
有时候在用vim打开文件时提示类似以下的信息: E325: 注意 发现交换文件 ".exportcert.cpp.swp" 所有者: liuchuanliang 日期: Th ...
- WordPress MORE+主题‘prettyPhoto’跨站脚本漏洞
漏洞名称: WordPress MORE+主题‘prettyPhoto’跨站脚本漏洞 CNNVD编号: CNNVD-201310-284 发布时间: 2013-10-23 更新时间: 2013-10- ...
- Linux kernel 内存损坏漏洞
漏洞名称: Linux kernel 内存损坏漏洞 CNNVD编号: CNNVD-201310-143 发布时间: 2013-10-11 更新时间: 2013-10-11 危害等级: 中危 漏洞类 ...
- Notice
13.793103448276 Notice: Undefined offset: -1 in C:\Zend\Apache2\htdocs\crawlWebsite\Crawl360.php on ...
- (转载)SQL联合查询中的关键语法
(转载)http://www.cnblogs.com/zhangliyu/archive/2009/03/21/1418215.html 联合查询效率较高.以下例子来说明联合查询的好处 t1表结构(用 ...