计算几何(凸包模板):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.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...
随机推荐
- 抓取Bing每日图片作为网站首页背景
把Bing搜索的背景图片设置为自己网站的背景,实现背景及资讯的每日更新 效果图如下: 理一下思路,首先我们要抓取Bing的每日图片及最新资讯,然后保存图片及信息到本地,最后显示图片及资讯到网站首页. ...
- 利用putty实现文件在linux上传和下载
利用putty实现文件上传和下载:1.打开windows命令提示符窗口d:(putty在d盘下)cd putty(pscp.exe所在目录)2:上传(主要利用pscp程序)pscp d:/jdk-8u ...
- ubuntu 13.10自定义启动顺序
添加PPA sudo add-apt-repository ppa:danielrichter2007/grub-customizer sudo apt-get update sudo apt-get ...
- Sdut 2164 Binomial Coeffcients (组合数学) (山东省ACM第二届省赛 D 题)
Binomial Coeffcients TimeLimit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 输入 输出 示例输入 1 1 10 2 9 ...
- Android从服务端获取json解析显示在客户端上面
Android从服务端获取json解析显示在客户端上面 百度经验:jingyan.baidu.com 首先说一下Json数据的最基本的特点,Json数据是一系列的键值对的集合,和XML数据来比,Jso ...
- open()函数
STDOUT_FILENO 1 标准输入 STDIN_FILENO 0 标准输出 STDERR_FILENO 2 标准错误 在/proc目 ...
- php 商务网站购物车联动地址
数据表如下: CREATE TABLE IF NOT EXISTS `china` (`region_id` smallint(5) unsigned NOT NULL, `parent_id` s ...
- PHP设计模式之工厂/单例/注册者模式
工厂模式 简单工厂模式 [静态工厂方法模式](Static Factory Method)是类的创建模式 工厂模式的几种形态: 1.简单工厂模式(Simple Factory)又叫做 静态工厂方法模式 ...
- Poco之ftp获取文件列表以及下载文件
#include <iostream>#include <string>#include <vector>#include <algorithm>#in ...
- 如何得到django中form表单里的复选框(多选框)的值( MultipleChoiceField )
直接写代码吧 CHECKBOX_CHOICES = ( ('Value1','Value1'), ('Value2','Value2'), ) class EditProfileForm(ModelF ...