博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) B. Bear and Blocks 水题
阅读量:4678 次
发布时间:2019-06-09

本文共 2298 字,大约阅读时间需要 7 分钟。

B. Bear and Blocks

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/573/problem/B

Description

Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification see picture for the first sample.

Limak will repeat the following operation till everything is destroyed.

Block is called internal if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time.

Limak is ready to start. You task is to count how many operations will it take him to destroy all towers.

Input

The first line contains single integer n (1 ≤ n ≤ 105).

The second line contains n space-separated integers h1, h2, ..., hn (1 ≤ hi ≤ 109) — sizes of towers.

Output

Print the number of operations needed to destroy all towers.

Sample Input

6

2 1 4 6 2 2

Sample Output

3

HINT

 

题意

每次会消除与外界相互接触的方块,问你得消除多少次,才能把所有方块都消除完

题解

对于每个数,我们统计一下从左边消除得消除多少次,从右边消除得消除多少次

然后O(n)跑一遍就好了

代码:

//qscqesze#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)#define maxn 200051#define mod 10007#define eps 1e-9int Num;//const int inf=0x7fffffff; //нчоч╢Сconst int inf=0x3f3f3f3f;inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}//**************************************************************************************int n;ll a[maxn];ll b[maxn];ll c[maxn];ll ans=0;int main(){ n=read(); for(int i=1;i<=n;i++) a[i]=read(); for(int i=1;i<=n;i++) b[i]=min(b[i-1]+1,a[i]); for(int i=n;i>=1;i--) c[i]=min(c[i+1]+1,a[i]); for(int i=1;i<=n;i++) ans=max(ans,min(b[i],c[i])); cout<
<

 

转载于:https://www.cnblogs.com/qscqesze/p/4770448.html

你可能感兴趣的文章
2016/03/16 codes
查看>>
2018年7月21日工作总结
查看>>
Linux shell 命令判断执行语法 ; , && , ||
查看>>
vim代码格式化插件clang-format
查看>>
What does the dot after dollar sign mean in jQuery when declaring variables?
查看>>
windows registry
查看>>
jquery 动画总结(主要指效果函数)
查看>>
【BZOJ4155】[Ipsc2015]Humble Captains
查看>>
【事件】阻止事件的冒泡
查看>>
mac os 安装 geckodriver
查看>>
【数据分析 R语言实战】学习笔记 第十一章 对应分析
查看>>
谁的青春不迷茫
查看>>
socket知识总结
查看>>
Qt做的简易图片浏览
查看>>
leetcode-17-电话号码的字母组合’
查看>>
Flume 示例
查看>>
Designing for Performance
查看>>
HTML属性的应用
查看>>
HEAP CORRUPTION DETECTED
查看>>
Android URI简单介绍
查看>>