Codeforces Round #318 D. Bear and Blocks

原创 2018年04月16日 20:37:38

D. Bear and Blocks
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.

Examples
inputCopy
6
2 1 4 6 2 2
outputCopy
3
inputCopy
7
3 3 3 1 3 3 3
outputCopy
2

超水的d题,不知道为什么才这么点人过。。。
第i列方格消失的时间取决于三个方面:i列的高度,左边一列完全消失的时间,右边一列完全消失的时间
状态转移方程即:dp[i]=min(dp[i-1]+1,dp[i+1]+1,h[i])

/* ***********************************************
Author        :ACagain
Created Time  :2018/4/13 19:08:48
File Name     :4_13.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define lson o<<1,l,m
#define rson o<<1|1,m+1,r
#define pii pair<int,int>
#define mp make_pair
#define ll long long
#define INF 0x3f3f3f3f
const int maxn=1e5+5;
int h[maxn],dp[maxn];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
      cin>>h[i];
    dp[0]=dp[n+1]=0;
    for(int i=1;i<=n;i++)
    {
        dp[i]=min(h[i],dp[i-1]+1);
    }
    int ans=0;
    for(int i=n;i>=1;i--)
    {
        dp[i]=min(dp[i],dp[i+1]+1);
        ans=max(dp[i],ans);
    }
    cout<<ans<<endl;
    return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38313974/article/details/79966101

Codeforces Round #318 D. Bear and Blocks DP

dp[i]表示第i列被消除需要的操作次数, dp[i] = min(i, n-i, h[i], dp[i-1]+1, dp[i+1]+1),,i、n-i表示每次消除边缘一列直到第i列的情况,h[i]表...
  • lyc19980424
  • lyc19980424
  • 2017-11-02 13:56:43
  • 25

codeforces 771D Bear ans Company 动态规划

E. Bear and Company time limit per test 1 second memory limit per test 256 megabytes inpu...
  • jijijix
  • jijijix
  • 2017-03-28 17:12:10
  • 562

CodeForces-771D-Bear and Company

我的博客
  • a962415287
  • a962415287
  • 2017-03-22 10:50:04
  • 403

573B. Bear and Blocks(Codeforces Round #318)

B. Bear and Blocks time limit per test 1 second memory limit per test 256 megabytes input stan...
  • caduca
  • caduca
  • 2015-08-30 03:36:45
  • 4421

Codeforces Round #318 573B. Bear and Blocks

题目链接:http://codeforces.com/problemset/problem/573/B 题        意:给你一个图形,每次都将最外层消除,问最多要几次才能全部消除。 思     ...
  • Seraphimon
  • Seraphimon
  • 2015-10-12 12:58:14
  • 271

Codeforces Round #444 (Div. 2)-贪心&尺取-Ratings and Reality Shows

http://codeforces.com/contest/887/problem/D 一个模特有两种活动。 ① 拍照片,挣钱 a。 ②开演唱会,花费b 给定模特这两种工作的时间表。 模特可以...
  • qq_35781950
  • qq_35781950
  • 2017-11-11 20:11:11
  • 197

Codeforces Round #426 (Div. 2) D. The Bakery(DP+线段树)

Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredient...
  • SSimpLe_Y
  • SSimpLe_Y
  • 2017-07-31 09:16:44
  • 1165

Codeforces Round #318 574D Bear and Blocks(dp)

D. Bear and Blocks time limit per test 1 second memory limit per test 256 megabytes input stan...
  • GKHack
  • GKHack
  • 2015-08-30 11:05:38
  • 928

codeforces573D. Bear and Cavalry

传送门:http://codeforces.com/problemset/problem/573/d 思路:首先如果没有限制,那么根据排序不等式,肯定按顺序匹配战士和马最好。 但是现在有了战士不能和自...
  • thy_asdf
  • thy_asdf
  • 2015-10-23 16:43:43
  • 423
收藏助手
不良信息举报
您举报文章:Codeforces Round #318 D. Bear and Blocks
举报原因:
原因补充:

(最多只允许输入30个字)