计算几何(凸包模板):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.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...
随机推荐
- 14_Xml继承
[工程截图] [Person.java] package com.HigginCui; public class Person { private String name; public String ...
- (hdu)5546 Ancient Go
Problem Description Yu Zhou likes to play Go with Su Lu. From the historical research, we found that ...
- java输入输出流总结 转载
一.基本概念 1.1 什么是IO? IO(Input/Output)是计算机输入/输出的接口.Java中I/O操作主要是指使用Java进行输入,输出操作. Java所有的I/O机制都是 ...
- 【原创】Linux 增加系统调用
Linux 增加系统调用大致步骤: 1.下载好内核文件,在内核源文件中添加好自己的调用函数. 2.编译内核 3.验证. 一.在内核源文件中增加自己的函数 首先将内核文件移至/usr/src/下并解 ...
- spring拦截器
一:拦截器配置 <!-- 拦截器 --> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path=&qu ...
- .NET异步操作学习之一:Async/Await中异常的处理
以前的异常处理,习惯了过程式的把出现的异常全部捕捉一遍,然后再进行处理.Async/Await关键字出来之后的确简化了异步编程,但也带来了一些问题.接下来自己将对这对关键字进行学习.然后把研究结果放在 ...
- git push用法和常见问题分析
在使用git 处理对android的修改的过程之中总结的.但不完善 Git push $ git push origin test:master // 提交本地test分支作为远程的m ...
- [转]jquery.timer用法
转自:http://www.cnblogs.com/guohui/archive/2012/02/24/2366668.html 来自JavaEye论坛的JQuery Timers应用知识 jQuer ...
- (转)搜索Maven仓库 获取 groupid artifactId
转载自:http://blog.csdn.net/z69183787/article/details/22188561 使用Maven进行开发的时候,比较常见的一个问题就是如何寻找我要的依赖,比如说, ...
- VPS用LNMP安装WordPress
前言 前几天,朋友手头上有一个空闲的vps,256M内存,我决定拿来玩一下.经过一番思考,还是用来挂站吧.然后看是CentOS6系统,果断决定用从来没玩过的LNMP.于是,百度.谷歌找教程,好多教程都 ...