zoukankan      html  css  js  c++  java
  • CF div2 318 D

    D. Bear and Blocks
     

    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 test(s)
    input
    6
    2 1 4 6 2 2
    output
    3
    input
    7
    3 3 3 1 3 3 3
    output
    2
    Note

    The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.

    After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation
    题目有点醉人,看了题解才知道可以转化为求双向连续数的最大值 如(1,2,3,......4,3,2,1)这样的最长的连续数的个数
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <algorithm>
    #include <cmath>
    
    using namespace std;
    
    const int M = 100005;
    
    typedef long long ll;
    
    vector <int>G[M];
    queue<int>Q;
    stack<int>st;
    int a[M];
    int r[M],l[M];
    int main()
    {
        int n;
        scanf("%d",&n);
        a[0] = a[n+1] = 0;
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        int ans = -1;
        memset(l,0,sizeof(l));
        memset(r,0,sizeof(r));
        for(int i=1;i<=n;i++){
            l[i] = min(l[i-1]+1,a[i]);
        }
        for(int i=n;i>=1;i--){
            r[i] = min(r[i+1]+1,a[i]);
        }
        for(int i=1;i<=n;i++){
            ans = max(ans,min(r[i],l[i]));
        }
    
        printf("%d
    ",ans);
    
    
        return 0;
    }
    View Code
    It is loneliness that make you different,not gregariousness
  • 相关阅读:
    [USACO18DEC]Fine Dining
    [USACO18DEC]Cowpatibility(容斥 or bitset优化暴力)
    [P2387魔法森林
    P4172 [WC2006]水管局长
    P2486 [SDOI2011]染色
    P3950部落冲突
    P4332三叉神经树
    莫比乌斯反演习题总结
    牛客 斐波那契数列问题的递归和动态规划3
    牛客 统计和生成所有不同的二叉树
  • 原文地址:https://www.cnblogs.com/lmlyzxiao/p/4811952.html
Copyright © 2011-2022 走看看