题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1670

单调栈维护凸包即可,用叉积判断;

维护上凸壳,然后把所有点的纵坐标翻转再求上凸壳即可,要注意排序规则略有变化。

代码如下:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef double db;
int const xn=;
db const eps=1e-;
int n,top,mx;
db ans;
struct N{
db x,y;
N(db x=,db y=):x(x),y(y) {}
bool operator < (const N &b) const
{return x<b.x||(x==b.x&&y<b.y);}
}p[xn],sta[xn];
bool cmp(N a,N b){return a.x<b.x||(a.x==b.x&&a.y>b.y);}
N operator - (const N &a,const N &b){return N(a.x-b.x,a.y-b.y);}
int rd()
{
int ret=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=; ch=getchar();}
while(ch>=''&&ch<='')ret=ret*+ch-'',ch=getchar();
return f?ret:-ret;
}
int maxx(int x,int y){return x<y?y:x;}
db sqr(db x){return x*x;}
db cross(N a,N b){return a.x*b.y-a.y*b.x;}
db len(N a){return sqrt(sqr(a.x)+sqr(a.y));}
db dis(N a,N b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));}
int dmp(db x){if(fabs(x)<=eps)return ; return x>eps?:-;}
void work()
{
top=;
for(int i=;i<=n;i++)
{
while(top>&&dmp(cross(sta[top]-sta[top-],p[i]-sta[top]))>=)top--;
sta[++top]=p[i];
}
while(top>)ans+=len(sta[top]-sta[top-]),top--;
}
int main()
{
n=rd(); mx=;
for(int i=;i<=n;i++)p[i].x=rd(),p[i].y=rd(),mx=maxx(mx,p[i].y);
sort(p+,p+n+);
work();
for(int i=;i<=n;i++)p[i].y=mx-p[i].y+;
sort(p+,p+n+,cmp);//
work();
printf("%.2f\n",ans);
return ;
}

bzoj 1670 Building the Moat护城河的挖掘 —— 凸包的更多相关文章

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

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

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

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

  3. bzoj1670 Usaco2006 Building the Moat护城河的挖掘 [凸包模板题]

    Description 为了防止口渴的食蚁兽进入他的农场,Farmer John决定在他的农场周围挖一条护城河.农场里一共有N(8<=N<=5,000)股泉水,并且,护城河总是笔直地连接在 ...

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

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

  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. 【BZOJ】1670: [Usaco2006 Oct]Building the Moat护城河的挖掘(凸包)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1670 裸打了凸包.. #include <cstdio> #include <cs ...

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

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

  9. BZOJ 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘

    Description 求凸包周长. Sol 凸包+计算几何. 这好像叫什么 Graham Scan 算法... 这个可以求凸包的周长,直径,面积. 选择一个基点,然后按极角排序,最后用一个栈一直维护 ...

随机推荐

  1. DP(正解完全背包+容斥)

    DP Time Limit:10000MS     Memory Limit:165888KB     64bit IO Format:%lld & %llu Submit Status De ...

  2. python脚本分析nginx访问日志

    日志格式如下: 223.74.135.248 [11/May/2017:11:19:47 +0800] "POST /login/getValidateCode HTTP/1.1" ...

  3. 右键打开cmd

    Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\shell\OpenCmdHere]@="Open cmd ...

  4. iOS 运行时详解

    注:本篇文章转自:http://www.jianshu.com/p/adf0d566c887 一.运行时简介 Objective-C语言是一门动态语言,它将很多静态语言在编译和链接时期做的事放到了运行 ...

  5. 【python】-- 类的继承(新式类/经典类)、多态

    继承 之前我们说到了类的公有属性和类的私有属性,其实就是类的封装,现在准备随笔的 是继承,是面向对象的第二大特性. 面向对象编程 (OOP) 语言的一个主要功能就是“继承”.继承是指这样一种能力:它可 ...

  6. CF1060 E-Sergey and Subway

    题目戳这里 一句话题意 一棵树,任意相隔一个点的两个点连一条新边(原边留下),问所有点对的距离之和. Solution 本来看见是黑题有点怕,但仔细一想也没有那么难. 先处理出每个点的深度(dep)和 ...

  7. Shell传参的多种方式

    Shell 传参的多种方式 使用$1 $2 这种类似占位符的方式 # 命令行调用 start.sh 8080 9090 # 脚本中获取 port1=$1 # 8080 port2=$2 # 9090 ...

  8. easy_install和pip的安装及使用

    在终端输入命令报错后,在网上找到了这篇博客,用easy_install命令安装pip,问题解决 Fatal error in launcher: Unable to create process us ...

  9. LeetCode:删除排序链表中的重复元素【83】

    LeetCode:删除排序链表中的重复元素[83] 题目描述 给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次. 示例 1: 输入: 1->1->2 输出: 1->2 示 ...

  10. spring-boot3

    更多的配置: # =================================================================== # COMMON SPRING BOOT PR ...