TTTTTTTTTTTTTTTTTT Gym 100851L 看山填木块
Problem L. Landscape Improved
Input file: landscape.in
Output file: landscape.out
Louis L Le Roi-Univers has ordered to improve the landscape that is seen from the royal palace. His
Majesty prefers to see a high mountain.
The Chief Landscape Manager is going to raise a mountain for Louis. He represents a landscape as a
flat picture on a grid of unit squares. Some of the squares are already filled with rock, while others are
empty. This greatly simplifies the design. Unit squares are small enough, and the landscape seems to be
smooth from the royal palace.
The Chief Landscape Manager has a plan of the landscape — the heights of all rock-filled columns for
each unit of width. He is going to add at most n square units of stones atop of the existing landscape to
make a mountain with as high peak as possible. Unfortunately, piles of stones are quite unstable. A unit
square of stones may be placed only exactly on top of the other filled square of stones or rock, moreover
the squares immediately to the bottom-left and to bottom-right of it should be already filled.
Existing landscape
Improved landscape
Your task is to help The Chief Landscape Manager to determine the maximum height of the highest
mountain he can build.
Input
The first line of the input file contains two integers w — the width of the existing landscape and n —
the maximum number of squares of stones to add (1 ≤ w ≤ 100 000, 0 ≤ n ≤ 1018).
Each of the following w lines contains a single integer hi — the height of the existing landscape column
(1 ≤ hi ≤ 109
).
Output
The output file shall contain the single integer — the maximum possible landscape height after at most
n unit squares of stones are added in a stable way.
Sample input and output
landscape.in landscape.out
8 4
3 100
题意:这题是给你w列方格,然后给你n个方块,让你加进去,使得这个图变得最高,加的要求是,如果这块的下面,以及左下右下都有,才能放
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#include <queue>
#include <vector>
#define MM(a,b) memset(a,b,sizeof(a));
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
#define CT continue
#define SC scanf
const int N=1e5+10;
int h[N],l[N],r[N];
ll sum[N];
int n; ll w; bool ok(int mid)
{
MM(r,inf);MM(l,0);
for(int i=1;i<=n;i++) {
ll a=i-(mid-h[i]),
b=i+(mid-h[i]);
if(a>=1) r[a]=min(r[a],i);
if(b<=n) l[b]=max(l[b],i);
}
for(int i=1;i<=n;i++) l[i]=max(l[i],l[i-1]);
for(int i=n;i>=1;i--) r[i]=min(r[i],r[i+1]);
for(int i=1;i<=n;i++) {
if(l[i]==0||r[i]==inf) CT;
ll all=0;
int k1=i-(l[i]+1)+1;
all+=((ll)k1)*mid-((ll)k1)*(k1-1)/2LL;
int k2=(r[i]-1)-i+1;
all+=((ll)k2)*mid-((ll)k2)*(k2-1)/2LL;
all-=mid;
if(all-(sum[r[i]-1]-sum[l[i]])<=w) return true;
}
return false;
} int main()
{
freopen("landscape.in","r",stdin);
freopen("landscape.out","w",stdout);
while(~SC("%d%lld",&n,&w))
{
int maxn=0;
MM(sum,0);
for(int i=1;i<=n;i++) {
SC("%d",&h[i]);
maxn=max(maxn,h[i]);
sum[i]=sum[i-1]+h[i];
}
int la=maxn,ra=2*1e9;
while(ra-la>1){
int mid=(la+(ll)ra)>>1;
if(ok(mid)) la=mid;
else ra=mid;
}
printf("%d\n",la);
}
return 0;
}
TTTTTTTTTTTTTTTTTT Gym 100851L 看山填木块的更多相关文章
- BZOJ 3368 约翰看山(扫描)O(N)
这题,简直丧心病狂了. 大意是给你一个环上一些覆盖的区间,让你求总覆盖长度. 非常坑的点是这个区间因为是个环,所以可能逆时针给你,也可能顺时针给你,你特别要注意.那么区分顺时针和逆时针的方法 就是,题 ...
- Gym - 100851L:Landscape Improved (二分+单调性)
题意: 一个宽度为N的网格图,i上有h[i]高的方块.现在你有W个方块,问怎么放使得最终的最高点最高. 当一个格子的下方,左下方和右下方都有方块那么久可以把方块放到这个格子上.最左端和最右端不能放 ...
- 冰雪奇缘,白色世界:四个IT人的四姑娘山双桥沟游记
去年9月初去了川西的稻城亚丁,体会了金色世界秋日童话,还写了一篇游记<从你的全世界路过-一群程序员的稻城亚丁游记>,也是得到了很多朋友和童鞋的点赞.今年11月初趁着周末的两天时间和朋友去了 ...
- 《Debug Hacks》和调试技巧【转】
转自:https://blog.csdn.net/sdulibh/article/details/46462529 Debug Hacks 作者为吉冈弘隆.大和一洋.大岩尚宏.安部东洋.吉田俊辅,有中 ...
- 你都用python来做什么?
首页发现话题 提问 你都用 Python 来做什么? 关注问题写回答 编程语言 Python 编程 Python 入门 Python 开发 你都用 Python 来做什么? 发现很 ...
- 爬虫--requests讲解
什么是requests? Requests是用Python语言编写,基于urllib,采用Apache2 Licensed 开源协议的HTTP库.它比urllib更加方便,可以节约我们大量的工作,完全 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- THINKPHP源码学习--------验证码类
TP3.2验证码类的理解 今天在学习中用到了THINKPHP验证码,为了了解究竟,就开始阅读TP验证码的源码. 源码位置:./ThinkPHP/Library/Think/Verify.class.p ...
- 浅析Yii2的view层设计
Yii2.0的view层提供了若干重要的功能:assets资源管理,widgets小组件,layouts布局... 下面将通过对Yii2.0代码直接进行分析,看一下上述功能都是如何实现的,当然细枝末节 ...
随机推荐
- 数据分析—win7+ipython+notebook安装
先安装python 3.x 然后 cmd 执行 pip3 ipython 然后 cmd 执行 pip3 install jupyter notebook 然后 cmd 执行 jupyter noteb ...
- RPA自定义脚本打开文件夹
import os import subprocess from rpa.web.common.utils import convert_2_unicode def startfile(filenam ...
- 【第一季】CH05_FPGA设计Verilog基础(二)Enter a post title
[第一季]CH05_FPGA设计Verilog基础(二) 5.1状态机设计 状态机是许多数字系统的核心部件,是一类重要的时序逻辑电路.通常包括三个部分:一是下一个状态的逻辑电路,二是存储状态机当前状态 ...
- 【深度森林第三弹】周志华等提出梯度提升决策树再胜DNN
[深度森林第三弹]周志华等提出梯度提升决策树再胜DNN 技术小能手 2018-06-04 14:39:46 浏览848 分布式 性能 神经网络 还记得周志华教授等人的“深度森林”论文吗?今天, ...
- uva 10325基础容斥
题目:给你一个数n以及m个数字,问1~n中不能被这m个数字整除的数字的个数. 分析:容斥原理.组合数学.数字1-n中能被a.b整除的数字的个数分别是n/a,n/b: 则1-n中能被a或b整数的数字个数 ...
- http GET 和 POST 请求的优缺点和误区
(1)post更安全(不会作为url的一部分,不会被缓存.保存在服务器日志.以及浏览器浏览记录中) (2)post发送的数据更大(get有url长度限制) (3)post能发送更多的数据类型(get只 ...
- LeetCode 腾讯精选50题--二叉树的最大深度
求二叉树的最大深度, 基本思路如下: 设定一个全局变量记录二叉树的深度,利用递归,没遍历一层都将临时深度变量+1,并在每一节点递归结束后判断深度大小. 具体代码如下: package algorith ...
- javaScript节流与防抖
一.节流(throttle) 用来实现阻止在短时间内重复多次触发同一个函数.主要用途:防止使用脚本循环触发网络请求的函数的恶意行为,确保请求的真实性(当然也包括其他阻止高频触发行为的应用): 实现原理 ...
- Linux下创建NFS来实现共享文件
简介说明: 在项目生产环境我们经常需要实现文件共享,传统的常见方案是通过NFS,实现服务器之间共享某一块磁盘,通过网络传输将分散的文件集中存储在一块指定的共享磁盘,实现基本的文件共享.实现这种方案,分 ...
- sql 基础语法使用
SQL的一些基础查询语法 基础.限定.模糊查询 关键字都是大写. 使用 BETWEENN AND 的时候小的数字或者日期放到 AND(并且) 的面前,大的一个放到AND 后面. 示例 ...