Bear and Blocks

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard 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.

题意: 就是给你N个高度,每次删除和外界相接触的方块,问多少次可以删完

竟然是Dp

对于每一个高度, 其决定值得是两边的高度,然而直接暴力T了,应该Dp

Dp【i】表示 第i个高度在第几秒会被完全删完

从左往右考虑一次, 从右往左考虑一次

然后对于每个 Dp值取min, 所有值取MAX;

(感谢学长ChildOfHulu♂指导)

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
int Num[maxn];
int Dp[maxn];
int Dp2[maxn];
set<int> S;
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n;
cin >> n;
for(int i = ; i <= n; ++i)
{
//int t;
cin >> Num[i];
}
for(int i = ; i <= n; ++i)
Dp[i] = min(Dp[i-]+,Num[i]);
for(int i = n; i >= ; i--)
Dp2[i] = min(Dp2[i+]+,Num[i]);
int ans = ;
for(int i = ; i <= n; ++i)
ans = max(ans, min(Dp[i],Dp2[i]));
cout << ans << endl;
}

CF 573B的更多相关文章

  1. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  2. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  3. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  4. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  5. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  6. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  7. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  8. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

  9. CF #375 (Div. 2) D. bfs

    1.CF #375 (Div. 2)  D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...

随机推荐

  1. python学习路线--从入门到入土

    入门技术博客 进阶自己挑选 入门基础 Python入门相对容易又可以干很多事(网站,运维,数据,爬虫等),是一门方便的工具语言.2016年TIOBE排名显示Python已经名列第四,成为脚本语言之首. ...

  2. springBoot中实现自定义属性配置、实现异步调用、多环境配置

    springBoot中其他相关: 1:springBoot中自定义参数: 1-1.自定义属性配置: 在application.properties中除了可以修改默认配置,我们还可以在这配置自定义的属性 ...

  3. VS Code使用 Vue工程配置 eslint

    首先确保VS Code 安装了 Vetur 和 Eslint 插件. VS CODE :文件 =>首选项 => 设置   (有3个点 或 {} 这样的大括号,打开setting.json) ...

  4. Java集合操作精华总结

    一.Set1.HashSet boolean add(E e) 添加 访问 boolean remove(E e) 删除 Iterator<E> iterator 遍历 int size( ...

  5. Android MediaPlayer播放raw资源封装类

    import android.content.Context; import android.media.MediaPlayer; import xxxx.R; public class MediaU ...

  6. 让WeuiPicker隐藏日期中的日,只保留年月

    weui.datePicker({ start: 1990, end: new Date().getFullYear() + 3, defaultValue: [year, month, 1], on ...

  7. Java控制台微动画输出 “草泥马神兽”

    public static void gameClearance() { String s = "\r      ┏┛ ┻━━━━━┛ ┻┓\r      ┃ ┃\r      ┃ ━ ┃\ ...

  8. spring boot2 整合(一)Mybatis (特别完整!)

    大概介绍下流程: 借助idea实现mybatis逆向工程 用xml配置实现整合 用cmd命令行实现mybatis逆向工程 用mapping.xml配置实现数据交互 用注解的方式实现数据交互 首先我的开 ...

  9. 基础的POJ学习

    OJ上的一些水题(可用来练手和增加自信)(poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094) 初期: 一. ...

  10. Python常用模块之time模块

    python中的time和datetime模块是时间方面的模块 time模块中时间表现的格式主要有三种: 1.timestamp:时间戳,时间戳表示的是从1970年1月1日00:00:00开始按秒计算 ...