题目: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. EasyDarwin开源流媒体服务器Golang版本:拉转推功能之拉流实现方法

    EasyDarwin开源流媒体服务器(www.easydarwin.org),拉转推是一个很有意义的功能,它可将一个独立的RTSP数据源"拉"到服务器,再通过转发协议转发给多个客户 ...

  2. debian安装oracle jdk

    1 去官网下载linux jdk https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.htm ...

  3. Mybatis sql注入问题

    预编译方式,即PreparedStatement,可以防注入:#{id} <select id="getBlogById" resultType="Blog&quo ...

  4. 【学员管理系统】0x02 学生信息管理功能

    [学员管理系统]0x02 学生信息管理功能 写在前面 项目详细需求参见:Django项目之[学员管理系统] Django框架大致处理流程 捋一下Django框架相关的内容: 浏览器输入URL到页面展示 ...

  5. linux c编程:线程创建

    前面章节中介绍了进程.从这一章开始介绍线程.进程和线程的差别是什么呢: 进程是具有一定独立功能的程序关于某个数据集合上的一次运行活动,进程是系统进行资源分配和调度的一个独立单位.  线程是进程的一个实 ...

  6. ionic添加scss

    Setup Sass Automatically 在进行以下操作之前要确保node比较新,以便正确安装node-sass 或 改用cnpm install node-sass安装(淘宝源) $ ion ...

  7. PAT 天梯赛 L2-009. 抢红包 【排序】

    题目链接 https://www.patest.cn/contests/gplt/L2-009 思路 用结构体存储,然后结构体排序 注意一下 个人编号是从 1 开始 计数的 AC代码 #include ...

  8. [原创]java WEB学习笔记01:javaWeb之tomcat的安装和配置

    本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...

  9. redis实现session共享,哨兵

    一.Redis介绍 1.redis是key-value的存储系统,属于非关系型数据库 2.特点:支持数据持久化,可以让数据在内存中保存到磁盘里(memcached:数据存在内存里,如果服务重启,数据会 ...

  10. 造成segmentation fault的可能原因分析

    一 造成segment fault,产生core dump的可能原因 1.内存访问越界 a) 由于使用错误的下标,导致数组访问越界 b) 搜索字符串时,依靠字符串结束符来判断字符串是否结束,但是字符串 ...