计算几何(凸包模板):HDU 1392 Surround the Trees
The diameter and length of the trees are omitted, which means a tree can be seen as a point. The thickness of the rope is also omitted which means a rope can be seen as a line.

There are no more than 100 trees.
Input
Zero at line for number of trees terminates the input for your program.
Output
Sample Input
9
12 7
24 9
30 5
41 9
80 7
50 87
22 9
45 1
50 7
0
Sample Output
243.06
这道题就是凸包模板。
http://www.cnblogs.com/jbelial/archive/2011/08/05/2128625.html
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const double eps=1e-;
const int N=;
struct Point{
double x,y;
Point(double x_=,double y_=){x=x_;y=y_;}
friend Point operator-(Point a,Point b){
return Point(a.x-b.x,a.y-b.y);
}
}p[N],st[N];
double sqr(double x){return x*x;}
double dis(Point a,Point b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));}
double cross(Point a,Point b){return a.x*b.y-a.y*b.x;}
bool cmp(Point a,Point b){
double s=cross(a-p[],b-p[]);
if(fabs(s)>=eps)return s>=eps;
return dis(a,p[])<dis(b,p[]);
}
int n,t,top;
double ans;
int main(){
while(scanf("%d",&n)!=EOF&&n){
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
if(n==){
puts("0.00");
continue;
}
if(n==){
printf("%.2f\n",dis(p[],p[]));
continue;
}
t=;
for(int i=;i<n;i++)if(p[i].y<p[t].y||p[i].y==p[t].y&&p[i].x<p[t].x)t=i;
if(t)swap(p[],p[t]);
sort(p+,p+n,cmp);
p[n]=p[];top=;
st[++top]=p[];
st[++top]=p[];
st[++top]=p[];
for(int i=;i<=n;i++){
while(top>=&&cross(st[top]-p[i],st[top-]-p[i])>=)top--;
st[++top]=p[i];
}
ans=;
for(int i=;i<=top;i++)ans+=dis(st[i],st[i-]);
printf("%.2f\n",ans);
}
return ;
}
计算几何(凸包模板):HDU 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 凸包模板
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 (凸包周长)
题目链接:HDU 1392 Problem Description There are a lot of trees in an area. A peasant wants to buy a rope ...
- 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(几何 凸包模板)
http://acm.hdu.edu.cn/showproblem.php?pid=1392 题目大意: 二维平面给定n个点,用一条最短的绳子将所有的点都围在里面,求绳子的长度. 解题思路: 凸包的模 ...
- HDU 1392 Surround the Trees(凸包*计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...
随机推荐
- Struts2的输入校验
一.Struts2提供了基于验证框架的输入校验,在这种校验方式下,所有的输入校验只需要编写简单的配置文件,Struts2的验证框架将会负责进行服务器校验和客户端校验. 校验失败后将Struts2将自动 ...
- jQuery分析(3) - jQuery.fn.init
1.前言 上一篇jQuery分析(2)中了解了jQuery库的骨架实现原理,这就好比摇滚音乐,摇滚音乐不是某种音乐他就像一个音乐盒子,里面包含了各种不同的摇滚风格(山地.朋克.乡村.流行.硬摇.金属. ...
- google模拟各种Android手机浏览器方法
在开始--运行 输入 chrome.exe --user-agent="Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/ ...
- 【C++11】新特性——Lambda函数
本篇文章由:http://www.sollyu.com/c11-new-lambda-function/ 文章列表 本文章为系列文章 [C++11]新特性--auto的使用 http://www.so ...
- Android中的自定义属性的实现
Android开发中,如果系统提供的View组件不能满足我们的需求,我们就需要自定义自己的View,此时我们会想可不可以为自定义的View定义属性呢?答案是肯定的.我们可以定义自己的属性,然后像系统属 ...
- ASP.NET一些常用的东西
三层架构的命名: UI: User Interface (数据显示层 用户界面)BLL:Business Logic Layer (业务逻辑层)DAL:Data Access Layer (数据访问层 ...
- Web Service 的服务端的引用
1.先说说服务端的引用 先写一个Web Service 的文件 上图 创建一个web 项目或者网站 然后添加新项 创建一个web服务 得到 下面的页面 然后运行起来 然后复制下地址 接下来创建另一 ...
- easy ui tabs 顶部绑定事件
$(function(){ $('#tb').tabs('bindclick', function(index, title){ }); }); $.extend($.fn.tabs. ...
- yii2源码学习笔记(二十)
Widget类是所有部件的基类.yii2\base\Widget.php <?php /** * @link http://www.yiiframework.com/ * @copyright ...
- Django web 开发指南 no such table:
在学习django web开发指南时,发布新博客点击save后会有error提示:no such table balabalabala... 百度了一下说重新运行manage.py syncdb 就可 ...