codeforces 573b Bear and Blocks
2016-07-17 18:22
399 查看
http://www.aichengxu.com/view/1753982
据这个大神说,这是一道dp题,但是我暂时还不理解。
什么时候可以dp,如何dp?
先记录下来再说了。
Bear and Blocks
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status
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 ofhi 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
Input
Output
Input
Output
Hint
The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.
View Code
据这个大神说,这是一道dp题,但是我暂时还不理解。
什么时候可以dp,如何dp?
先记录下来再说了。
Bear and Blocks
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status
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 ofhi 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
Input
6 2 1 4 6 2 2
Output
3
Input
7 3 3 3 1 3 3 3
Output
2
Hint
The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.
#include<iostream> #include<stdio.h> using namespace std; const int maxx = 100005; int h[maxx]; int l[maxx]; int r[maxx]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&h[i]); h[0]=h[n+1]=0; for(int i=1;i<=n;i++) { l[i]=min(l[i-1]+1,h[i]); r[n-i+1]=min(r[n-i+2]+1,h[n-i+1]); } int ans=0; for(int i=1;i<=n;i++) { ans=max(ans,min(l[i],r[i])); } cout<<ans<<endl; return 0; }
View Code
相关文章推荐
- CocoaAsyncSocket源码解析
- Codeforces Round #311 (Div. 2) C 贪心
- 。。。。
- AFNetWorking源码解析
- 编写xml文件时,The markup in the document preceding the root element must be well-formed.等bug
- SDWebImage源码解析
- Exchange 2010更改断开连接的邮箱的保留时间
- 单例模式
- iOS开发从入门到精通--UIViewController使用
- java performance
- matlab 读取图片的格式
- [安卓开发] 自定义View之一: 组合View
- 正则表达式
- HTML有2种路径的写法:绝对路径和相对路径
- hdu_2222_Keywords Search(AC自动机板子)
- CenterOS6.5(Minimal) 搭建Redis
- hdu_2222_Keywords Search(AC自动机板子)
- 数据结构—栈
- exchange2010启用邮箱存档功能
- GitHub 排名前 100 的安卓项目简介