Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) B. Bear and Blocks 水题
B. Bear and Blocks
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/573/problem/B
Description
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 Input
6
2 1 4 6 2 2
Sample Output
3
HINT
题意
每次会消除与外界相互接触的方块,问你得消除多少次,才能把所有方块都消除完
题解:
对于每个数,我们统计一下从左边消除得消除多少次,从右边消除得消除多少次
然后O(n)跑一遍就好了
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200051
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int n;
ll a[maxn];
ll b[maxn];
ll c[maxn];
ll ans=;
int main()
{
n=read();
for(int i=;i<=n;i++)
a[i]=read();
for(int i=;i<=n;i++)
b[i]=min(b[i-]+,a[i]);
for(int i=n;i>=;i--)
c[i]=min(c[i+]+,a[i]);
for(int i=;i<=n;i++)
ans=max(ans,min(b[i],c[i]));
cout<<ans<<endl;
}
Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) B. Bear and Blocks 水题的更多相关文章
- VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) E. Correcting Mistakes 水题
E. Correcting Mistakes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...
- 校内选拔I题题解 构造题 Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) ——D
http://codeforces.com/contest/574/problem/D Bear and Blocks time limit per test 1 second memory limi ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
- Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...
- Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos 水题
A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...
- Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...
- Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题
A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...
- Codeforces Beta Round #9 (Div. 2 Only) B. Running Student 水题
B. Running Student 题目连接: http://www.codeforces.com/contest/9/problem/B Description And again a misfo ...
随机推荐
- Java基础——I/O
文本I/O与二进制I/O 在计算机中所有的文件都是以二进制的形式来存储的,所以本质上所有的文件都是二进制文件. 文本I/O建立在二进制I/O的基础之上,它能提供字符层次的编码和解码的抽象,在写入一个字 ...
- 【转】Android之NetworkOnMainThreadException异常
看名字就应该知道,是网络请求在MainThread中产生的异常 先来看一下官网的解释: Class Overview The exception that is thrown when an appl ...
- Android 生成含签名文件的apk安装包
做android开发时,必然需要打包生成apk文件,这样才能部署.作为一个完善的apk,必然少不了签名文件,否则下次系统无法进行更新. 一.签名文件的制作及打包生成APK文件 签名文件比较流行的制作方 ...
- 从网页监听Android设备的返回键
最近搞Android项目的时候,遇到一个比较蛋疼的需求,需要从Client App调用系统浏览器打开一个页面,进行杂七杂八的一些交互之后,返回到App.如何打开浏览器和如何返回App这里就不说了,有兴 ...
- [Papers]NSE, $u_3$, Lebesgue space [Jia-Zhou, NARWA, 2014]
$$\bex u_3\in L^\infty(0,T;L^\frac{10}{3}(\bbR^3)). \eex$$
- Spring 事务管理原理探究
此处先粘贴出Spring事务需要的配置内容: 1.Spring事务管理器的配置文件: 2.一个普通的JPA框架(此处是mybatis)的配置文件: <bean id="sqlSessi ...
- ISAPI在IIS7上的配置
主要介绍ISAPI的作用.ISAPI在IIS7上的配置.开发ISAPI的基本内容及使用VS 2008配置ISAPI DLL开发项目. 一.ISAPI介绍 缩写词=Internet Server App ...
- Delphi 操作Word怎么控制光标的位置
unit ControlWordS; interface uses Classes, Sysutils, Word97; type TControlWord = class(TComponent) ...
- [Hive - LanguageManual] Alter Table/Partition/Column
Alter Table/Partition/Column Alter Table Rename Table Alter Table Properties Alter Table Comment Add ...
- mvn deploy 报错:Return code is: 400, ReasonPhrase: Bad Request. ->
mvn deploy 报错:Return code is: 400, ReasonPhrase: Bad Request. -> TEST通过没有报错,但是最终部署到Nexus中时出现错误. 后 ...