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 ...
随机推荐
- 反编译Android APK及防止APK程序被反编译
怎么逆向工程对Android Apk 进行反编译 google Android开发是开源的,开发过程中有些时候会遇到一些功能,自己不知道该怎么做,然而别的软件里面已经有了,这个时候可以采用反编译的方式 ...
- ArrayList与LinkedList实现比较
1.ArrayList实现是基于数组来实现的,这可由ArrayList的源码看出: public class ArrayList<E> extends AbstractList<E& ...
- JENKINS里,如何为SLAVE配置多个不同的JAVA环境?
今天遇到这个问题了, 原来在MASTER配置里可以统一管理的,不管这个路径有没有在MASTER上. 这样一来,JENKINS在编译时,会优先选用环境变量里的JAVA版本,然后才是MAVEN里的JAVA ...
- ANDROID_MARS学习笔记_S03_006_geocoding、HttpClient
一.简介 二.代码1.xml(1)AndroidManifest.xml <uses-permission android:name="android.permission.ACCES ...
- while +next 循环 回到循环顶端
my $show_tip = 1; sub login { while (1) { my $api ="https://login.weixin.qq.com/cgi-bin/mmwebwx ...
- 【CF】174 Div.1 B Cow Program
思路是树形DP+状态压缩.其实仅有2个状态,奇数次来到x或者偶数次来到x.(因为对x的更新不同).同时开辟visit数组,解决环.注意,一旦遇到环结果就是-1.DP数组存放第奇数/偶数次来到x时,对y ...
- hadoop2.2编程:hadoop性能测试
<hadoop the definitive way>(third version)中的Benchmarking a Hadoop Cluster Test Cases 的class在新的 ...
- Ehcache Java开源缓存框架
一.ehcache.xml 配置详解 单机配置: <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...
- Ext.form.FormPanel定义的参数说明
1.formId : String (可选的)FORM标签的id(默认是自动生成的). 2.labelWidth : Number 标签的宽度.该属性级联于子容器. 3. itemCls : Stri ...
- Js 时间轴和拓扑图
http://code.csdn.net/news/2819345 http://visjs.org/