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代码直接进行分析,看一下上述功能都是如何实现的,当然细枝末节 ...
随机推荐
- django类视图的使用
1 类视图引入 以函数的方式定义的视图称为函数视图,函数视图便于理解. 但是遇到一个视图对应的路径提供了多种不同HTTP请求方式的支持时,便需要在一个函数中编写不同的业务逻辑,代码可读性与复用性都不佳 ...
- C# 使用Emit实现动态AOP框架 (二)
目 录 C# 使用Emit实现动态AOP框架 (一) C# 使用Emit实现动态AOP框架 (二) C# 使用Emit实现动态AOP框架 (三) C# 使用Emit实现动态AOP框架 进阶篇之异常处 ...
- async/await 的引用
static async void Start() { string s = "ass"; Console.WriteLine(getMemory(s)+"Hello W ...
- asp.net 自动检测缓存内容是否变化
1 使用cache.Insert方法时,新建一个System.Web.Caching.CacheDependency对象,告诉缓存,当缓存的内容发生变化时,将删除缓存,并重新缓存 using Syst ...
- 二、LinkList及其源码解析
1.链表介绍 链表是一种物理单元上非连续,非顺序的存储结构.链表由一系列的姐点组成,结点可以在运行时动态生成.每个结点包含两个部分,一个是存储数据元素的数据域,一个是存储下一个结点的指针域 双链表是链 ...
- easyUi 的form和validate组件
以下代码不能运行,只是我在学习过程中记录的笔记,但代码可以用!!! 可以按照需要截取. <%@ page language="java" contentType=" ...
- Lab3 Report
- STM32点亮LED
原理图 测试灯,接GPIO外设B,Pin 12 举例 前提,工程模版建立好 #include "stm32f10x.h" void delay(u32 i) { while(i-- ...
- 14.SpringMVC核心技术-类型转换器
类型转换器 在前面的程序中,表单提交的无论是 int 还是 double 类型的请求参数,用于处理该请求 的处理器方法的形参, 均可直接接收到相应类型的相应数据,而非接收到 String 再手工转换. ...
- InnoDB意向锁的作用
https://www.zhihu.com/question/51513268?sort=created IX,IS是表级锁,不会和行级的X,S锁发生冲突.只会和表级的X,S发生冲突. 意向锁是一种快 ...