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 <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
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-9
int Num;
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int n;
ll a[maxn];
ll b[maxn];
ll c[maxn];
ll ans=;
int main()
{
n=read();
for(int i=;i<=n;i++)
a[i]=read();
for(int i=;i<=n;i++)
b[i]=min(b[i-]+,a[i]);
for(int i=n;i>=;i--)
c[i]=min(c[i+]+,a[i]);
for(int i=;i<=n;i++)
ans=max(ans,min(b[i],c[i]));
cout<<ans<<endl;
}

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) B. Bear and Blocks 水题的更多相关文章

  1. VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) E. Correcting Mistakes 水题

    E. Correcting Mistakes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...

  2. 校内选拔I题题解 构造题 Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) ——D

    http://codeforces.com/contest/574/problem/D Bear and Blocks time limit per test 1 second memory limi ...

  3. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

  4. Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题

    A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  5. Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题

    B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...

  6. Codeforces Round #368 (Div. 2) A. Brain's Photos 水题

    A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...

  7. Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题

    A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...

  8. Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题

    A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...

  9. Codeforces Beta Round #9 (Div. 2 Only) B. Running Student 水题

    B. Running Student 题目连接: http://www.codeforces.com/contest/9/problem/B Description And again a misfo ...

随机推荐

  1. IE下JS接受ActiveX控件方法

    1.常规写法 <SCRIPT type="text/javascript" FOR="activexID" EVENT="onXXXevent( ...

  2. date.plugin.js 日期插件

    //定义命名空间 var DatePlugin; if (!DatePlugin) DatePlugin = {}; /*整理时间:2015-05-28*/ var defaultFormat = & ...

  3. ios 照片编辑的view封装

    转:http://www.cnblogs.com/xiaobaizhu/archive/2013/07/03/3170101.html 该控件有旋转,缩放,拖动,剪裁的功能,封装成了一个ImageCr ...

  4. SharePoint 2010 列表项事件接收器 ItemAdded 的使用方法

    列表项事件处理器是继承于Microsoft.SharePoint.SPItemEventReceiver的类,Microsoft.SharePoint.SPItemEventReceiver类提供了许 ...

  5. equals方法

    一.equals方法介绍 1.1.通过下面的例子掌握equals的用法 package cn.galc.test; public class TestEquals { public static vo ...

  6. xml-xml试题

    ylbtech-doc:xml-xml试题 xml试题 1.A,xml试题返回顶部 01.{XML题目}关于XML声明正确的是.(选择1项) A)<!xml version=”1.0”!> ...

  7. Android基于基于布局嵌套的页面导航实现

    页面如下: 主页面的布局分隔为三部分: 注意观察上面标记为红色的android:id均采用android系统默认的名称: 页面的导航组件: <?xml version="1.0&quo ...

  8. SDUT 3571 Password 暴力搜索

    这个题如果裸搜肯定超时了 但是我们可以枚举,用初始串的哪一位数字去填目标串的那一位数字 这样就是暴力6!,复杂度很低,然后需要解决过程中经过的点的问题, 因为是从左向右走,所以记录当前光标, 和当前达 ...

  9. <转>python version 2.7 required,which was not found in the registry

    安装PIL-1.1.7.win32-py2.7的时候,不能再注册表中识别出来python2.7 方法:新建一个register.py 文件,把一下代码贴进去,保存 # # script to regi ...

  10. DOM笔记(一):HTMLDocument接口

    操作HTML文档的第一步就是获取对文档元素的引用,每一个元素在DOM中就是一个节点,所有的元素在DOM中构成一个节点树. 用于获取元素节点定义的方法定义于HTMLDocument接口,window.d ...