计算几何(凸包模板):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.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...
随机推荐
- windows2008 x86 安装 32位oracle
1.windows 2008 升级到sp2补丁 下载地址 : http://www.microsoft.com/zh-cn/download/confirmation.aspx?id=15278 2. ...
- ios毛玻璃效果
方法一:支持所有ios系统版本: - (void)setupBlurView { UIImageView *darkView = [[UIImageView alloc] init]; darkVie ...
- Installshield: custom action return value
参考:MSDN: Custom Action Return Values 参考:MSDN: Logging of Action Return Values
- UDP协议疑难杂症全景解析
转载:http://blog.csdn.net/dog250/article/details/6896949 UDP协议疑难杂症全景解析 2011-10-22 19:26 2989人阅读 评论(4) ...
- MySQl索引创建
一.什么是索引? 索引用来快速地寻找那些具有特定值的记录,所有MySQL索引都以B-树的形式保存.如果没有索引,执行查询时MySQL必须从第一个记录开始扫描整个表的所有记录,直至找到符合要求的记录.表 ...
- java输入输出流总结 转载
一.基本概念 1.1 什么是IO? IO(Input/Output)是计算机输入/输出的接口.Java中I/O操作主要是指使用Java进行输入,输出操作. Java所有的I/O机制都是 ...
- 浅谈页面无刷新技术ajax
现在一般网站都是用ajax来实现页面无刷新操作的. 什么是无刷新:ajax可以实现页面与后台的数据交互,用户完全感觉不出页面有任何的刷新,这就是AJAX的无刷新. ajax方法实现: 可以对ajax进 ...
- TDirectory.Copy复制文件
描述:复制文件夹以及文件夹下的内容 procedure Copy(const SourceDirName, DestDirName: string) 参数一:源文件夹 参数二:目标文件夹 所在单元:S ...
- 韦东山教程ARM的时钟设置出现的问题及其解决方法
时钟设置是一个非常重要的环节,如果系统没有合适的时钟,根本无法工作. S3C2440的时钟复杂,分为FCLK,HCLK,PCLK. 在程序测试中,曾出现这样一个错误.系统当前FCLK为400 ...
- WebComponent
WebComponent 前言 最近加入到新项目组负责前端技术预研和选型,一直偏向于以Polymer为代表的WebComponent技术线,于是查阅各类资料想说服老大向这方面靠,最后得到的结果是:& ...