Description

为了防止口渴的食蚁兽进入他的农场,Farmer John决定在他的农场周围挖一条护城河。农场里一共有N(8<=N<=5,000)股泉水,并且,护城河总是笔直地连接在河道上的相邻的两 股泉水。护城河必须能保护所有的泉水,也就是说,能包围所有的泉水。泉水一定在护城河的内部,或者恰好在河道上。当然,护城河构成一个封闭的环。 挖护城河是一项昂贵的工程,于是,节约的FJ希望护城河的总长度尽量小。请你写个程序计算一下,在满足需求的条件下,护城河的总长最小是多少。 所有泉水的坐标都在范围为(1..10,000,000,1..10,000,000)的整点上,一股泉水对应着一个唯一确定的坐标。并且,任意三股泉水 都不在一条直线上。 以下是一幅包含20股泉水的地图,泉水用”*”表示


图中的直线,为护城河的最优挖掘方案,即能围住所有泉水的最短路线。
路线从左上角起,经过泉水的坐标依次是:(18,0),(6,-6),(0,-5),(-3,-3),(-17,0),(-7,7),(0,4),
(3,3)。绕行一周的路径总长为70.8700576850888(…)。答案只需要保留两位小数,于是输出是70.87。

Input

* 第1行: 一个整数,N * 第2..N+1行: 每行包含2个用空格隔开的整数,x[i]和y[i],即第i股泉水的位 置坐标

Output

* 第1行: 输出一个数字,表示满足条件的护城河的最短长度。保留两位小数

Sample Input

20
2 10
3 7
22 15
12 11
20 3
28 9
1 12
9 3
14 14
25 6
8 1
25 1
28 4
24 12
4 15
13 5
26 5
21 11
24 4
1 8

Sample Output

70.87
 /**/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int mxn=;
int n;
struct P{
int x,y;
}p[mxn],s[mxn];
int top=;
double sum=; inline int read(){
int x=,f=;
char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();};
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();};
return x*f;
}
inline P operator -(P a,P b){
P t; t.x=a.x-b.x; t.y=a.y-b.y; return t;
}
inline ll operator *(P a,P b){
return a.x*b.y-a.y*b.x;
}
inline ll dis(P a,P b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
inline bool operator < (P a,P b){
ll t=(a-p[])*(b-p[]);
if(t==)return dis(p[],a)<dis(p[],b);
return t>;
} void graham(){
int t=,i;
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;//找出y值最小点作为起点
swap(p[],p[t]);
sort(p+,p+n+);
s[++top]=p[];
s[++top]=p[];
for(i=;i<=n;i++){
while((s[top]-s[top-])*(p[i]-s[top-])<=) top--;//找到“更靠外的点”就舍弃栈顶的点
s[++top]=p[i];
}
s[top+]=p[];
for(i=;i<=top;i++){
sum+=sqrt(dis(s[i],s[i+]));//计算距离
}
return;
}
int main(){
n=read();
int i,j;
int x,y;
for(i=;i<=n;i++){
p[i].x=read();p[i].y=read();
}
graham();
printf("%.2lf\n",sum);
return ;
}

bzoj1670 Usaco2006 Building the Moat护城河的挖掘 [凸包模板题]的更多相关文章

  1. 【BZOJ-1670】Building the Moat护城河的挖掘 Graham扫描法 + 凸包

    1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec  Memory Limit: 64 MBSubmit: 464  Solv ...

  2. bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 -- 凸包

    1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec  Memory Limit: 64 MB Description 为了防止 ...

  3. bzoj 1670 [Usaco2006 Oct]Building the Moat护城河的挖掘——凸包

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1670 用叉积判断.注意两端的平行于 y 轴的. #include<cstdio> ...

  4. bzoj 1670 Building the Moat护城河的挖掘 —— 凸包

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1670 单调栈维护凸包即可,用叉积判断: 维护上凸壳,然后把所有点的纵坐标翻转再求上凸壳即可, ...

  5. bzoj1670【Usaco2006 Oct】Building the Moat 护城河的挖掘

    1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec  Memory Limit: 64 MB Submit: 387  Sol ...

  6. BZOJ_1670_[Usaco2006 Oct]Building the Moat护城河的挖掘_求凸包

    BZOJ_1670_[Usaco2006 Oct]Building the Moat护城河的挖掘_求凸包 Description 为了防止口渴的食蚁兽进入他的农场,Farmer John决定在他的农场 ...

  7. 牛客假日团队赛5J 护城河 bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 (凸包的周长)

    链接:https://ac.nowcoder.com/acm/contest/984/J 来源:牛客网 护城河 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...

  8. BZOJ1670 [Usaco2006 Oct]Building the Moat护城河的挖掘

    裸的凸包...(和旋转卡壳有什么关系吗...蒟蒻求教T T) 话说忘了怎么写了...(我以前都是先做上凸壳再做下凸壳的说) 于是看了下hzwer的写法,用了向量的点积,方便多了,于是果断学习(Orz) ...

  9. 【计算几何】【凸包】bzoj1670 [Usaco2006 Oct]Building the Moat护城河的挖掘

    #include<cstdio> #include<cmath> #include<algorithm> using namespace std; #define ...

随机推荐

  1. Jenkins学习七:Jenkins的授权和访问控制

    默认的Jenkins不包含任何的安全检查,任何人可以修改Jenkins设置,job和启动build等.显然地在大规模的公司需要多个部门一起协调工作的时候,没有任何安全检查会带来很多的问题. 在系统管理 ...

  2. 常用类库——StringBuffer类

    掌握目标: 1,掌握StringBuffer与String的区别. 2,掌握StringBuffer常用方法. 3,掌握StringBuffer实际应用. 1,认识StringBuffer. Stri ...

  3. 在Function对象上扩展method方法

    ;(function() { /** * 在Function对象上扩展method方法 * @param {String} name 扩展的方法名称 * @param {Function} callb ...

  4. 关于第一个Java应用

    一.创建Java源文件 Java应用由一个或多个扩展名为".java"的文件构成,这些文件被称为Java源文件,从编译的角度,则被称为编译单元(Compilation Unit). ...

  5. 023医疗项目-模块二:药品目录的导入导出-从数据库中查出数据用XSSF导出excel并存放在虚拟目录最后下载(包括调试)

    我们要实现的效果:     进入到这个页面后,输入要查询的条件,查询出药品表的数据,然后按下导出按钮 ,就会在服务器的一个目录下生成一个药品表的excel表格.  点击"导出"之后 ...

  6. [Erlang37]error/1 exit/1 exit/2 throw/1的区别

    1. error/1 主要是系统用来定义内部错误的: Erlang内建的run time error 一共有10种: function_clause/case_clause/if_clause/bad ...

  7. [py]导入模块3种方法

        import os <--通过os.system()引用 from os import * <---直接system()引用,不建议使用 from os import argv i ...

  8. C语言 二级指针内存模型②

    //二级指针第二种内存模型 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #incl ...

  9. Uploadify v3.2.1 属性、事件、方法说明

    一.属性 属性名称 默认值 说明 auto true 设置为true当选择文件后就直接上传了,为false需要点击上传按钮才上传 . buttonClass " 按钮样式 buttonCur ...

  10. 安装包制作工具 SetupFactory使用2 API清单

    2014-11-19 SetupFactory中可以通过其API控制很复杂的业务需求. 下图中展示了其内置的API种类与具体分类函数.   序号 API名称 API说明 1 Application.E ...