题目:
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.
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.
Print the number of operations needed to destroy all towers.
6 2 1 4 6 2 2
3
7 3 3 3 1 3 3 3
2
The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.

思路:首先由如下几点:
1.第i(i=0,1,2....n-1)个位置的塔最多需要min(i+1,n-i)次被打倒.可由数学归纳法证明。
2.当第i个位置的塔比第i-1个位置的塔高时,将这个塔打倒需要a[i-1]+1次。
3.打倒一座塔最多需要h[i]次
由上述几条可知,我们可以从左右两端去计算每座塔需要多少步被打倒,然后找到需要的次数最多的塔。
代码:
//By Sean Chen
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 100005
using namespace std;
int h[maxn],b[maxn],c[maxn];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&h[i]);
int pos=0;
b[0]=1;
for(int i=0;i<n;i++)
{
if(h[pos]+i-pos<h[i])
b[i]=h[pos]+i-pos;
else
{
b[i]=h[i];
pos=i;
}
b[i]=min(i+1,b[i]);
}
c[n-1]=1;
pos=n-1;
for(int i=n-2;i>=0;i--)
{
if(h[pos]+pos-i<h[i])
c[i]=h[pos]+pos-i;
else
{
c[i]=h[i];
pos=i;
}
c[i]=min(n-i,c[i]);
}
int ans=0;
for(int i=0;i<n;i++)
{
int temp=min(b[i],c[i]);
ans=max(temp,ans);
}
printf("%d\n",ans);
return 0;
}