zoukankan      html  css  js  c++  java
  • Codeforces Round #318 D. Bear and Blocks

    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;
    }
  • 相关阅读:
    C#制作windows屏保实战
    创建一个可以修改不可以删除的文件夹或文件,windows目录和文件权限实测总结
    分享一下我用C#写的贪吃蛇和迷宫
    用C#做的汉诺塔游戏以及对汉诺塔递归的简单理解
    纪念一下即将逝去的flash,曾今的flash入门学习示例《别盯着我》C#版
    C#中关于变量的作用域不易理解的特例
    列出文件夹和遍历文件夹的区别
    怎样创建无法直接删除的文件夹--关于windows权限的迷思
    用C#写的后台整点报时工具
    用C#写差异文件备份工具
  • 原文地址:https://www.cnblogs.com/acagain/p/9180714.html
Copyright © 2011-2022 走看看