bzoj 1670 Building the Moat护城河的挖掘 —— 凸包
题目: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护城河的挖掘 —— 凸包的更多相关文章
- bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 -- 凸包
1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec Memory Limit: 64 MB Description 为了防止 ...
- bzoj 1670 [Usaco2006 Oct]Building the Moat护城河的挖掘——凸包
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1670 用叉积判断.注意两端的平行于 y 轴的. #include<cstdio> ...
- bzoj1670 Usaco2006 Building the Moat护城河的挖掘 [凸包模板题]
Description 为了防止口渴的食蚁兽进入他的农场,Farmer John决定在他的农场周围挖一条护城河.农场里一共有N(8<=N<=5,000)股泉水,并且,护城河总是笔直地连接在 ...
- 【BZOJ-1670】Building the Moat护城河的挖掘 Graham扫描法 + 凸包
1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 464 Solv ...
- bzoj1670【Usaco2006 Oct】Building the Moat 护城河的挖掘
1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec Memory Limit: 64 MB Submit: 387 Sol ...
- BZOJ_1670_[Usaco2006 Oct]Building the Moat护城河的挖掘_求凸包
BZOJ_1670_[Usaco2006 Oct]Building the Moat护城河的挖掘_求凸包 Description 为了防止口渴的食蚁兽进入他的农场,Farmer John决定在他的农场 ...
- 【BZOJ】1670: [Usaco2006 Oct]Building the Moat护城河的挖掘(凸包)
http://www.lydsy.com/JudgeOnline/problem.php?id=1670 裸打了凸包.. #include <cstdio> #include <cs ...
- 牛客假日团队赛5J 护城河 bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 (凸包的周长)
链接:https://ac.nowcoder.com/acm/contest/984/J 来源:牛客网 护城河 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...
- BZOJ 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
Description 求凸包周长. Sol 凸包+计算几何. 这好像叫什么 Graham Scan 算法... 这个可以求凸包的周长,直径,面积. 选择一个基点,然后按极角排序,最后用一个栈一直维护 ...
随机推荐
- 在普通网页中如何调用html5+的plus对象
<script> //用法: HTML5+的plus对象,必须由click事件触发后,才能在普通网页中使用.所以在没有click的情况下,调用本文件可以解决问题! //在代码中使用: pl ...
- apache虚拟主机配置: 设置二级目录访问跳转
<VirtualHost *:> DocumentRoot "d:/www/abc" ServerName www.abc.com Alias /course &quo ...
- ThoughtWorks(中国) 程序员读书雷达
ThoughtWorks(中国)程序员读书雷达 软件业的特点是变化.若要提高软件开发的技能,就必须跟上技术发展的步伐.埋首醉心于项目开发与实战,固然能够锤炼自己的开发技巧,却难免受限于经验与学识.世界 ...
- android ui篇 自己写界面
对于一些较为简单的界面则自己进行写. 在这里就需要了解xml文件中一些基本的属性以及android手机的知识. 一.目前手机屏幕像素密度基本有5种情况.(以下像素密度简称密度) 密度 ldpi mdp ...
- tomcat调试页面的时候,不刷新
1.调试一个页面的时候,js文件不刷新,也就是相当于没有改(cache) 2.解决:在Server中将当前tomcat的模式改为debug即可
- [原创]Scala学习:关于变量(val,var,类型推断)
1.常量定义: val val 类似于java中的final变量.一旦初始化了,val就不能再被赋值 val megs = "hello world" 2.变量的定义: var ...
- web框架详解之 tornado 四 模板引擎、session、验证码、xss
一.模板引擎 基本使用 继承,extends 页面整体布局用继承 导入,include 如果是小组件等重复的那么就用导入 下面是目录 首先在controllers里面创建一个文件,文件里面是页面类 # ...
- Nginix安装教程(Ubuntu)
安装gcc g++的依赖库 #apt-get install build-essential #apt-get install libtool 安装 pcre依赖库 #sudo apt-get u ...
- EntityFramework 学习 一 Add New Entity using DBContext in Disconnected Scenario
using System; using System.Collections.Generic; public partial class Student { public Student() { th ...
- HDU 4001 To Miss Our Children Time(2011年大连网络赛 A 贪心+dp)
开始还觉得是贪心呢... 给你三类积木叫你叠楼房,给你的每个积木包括四个值:长 宽(可以互换) 高 类型d d=0:你只能把它放在地上或者放在 长 宽 小于等于 自己的积木上面 d=1:你只能把它放在 ...