Bear and Blocks CF-574D(类似dp+思维)
来源:互联网 发布:c语言whilet--的用法 编辑:程序博客网 时间:2024/05/17 07:51
原题链接
题意:高低不同的柱体,每次消去裸露的部分,问多少次能消完。
思路:其实每个柱体每次至少能缩短一个长度,而能不能加快点速度完全取决去他两边的柱体,如果他两边的柱体老是消不完,那他也一定消不完(除非他自己能一层层地减完),如果两边柱体消完了,那他在下一次操作就能马上消完。
也就是取决于i-1和i+1.
AC代码:
#include<cstdio>#include<iostream>#include<algorithm>#include<queue>#include<stack>#include<cstring>#include<string>#include<vector>#include<cmath>#include<map>using namespace std;typedef long long ll;#define mem(a,b) memset(a,b,sizeof(a))const int maxn = 1e6+5;const int ff = 0x3f3f3f3f;const double esp = 1e-7;int n;int h[maxn];int t[maxn];int main(){cin>>n;int ans = -1;for(int i = 1;i<= n;i++)scanf("%d",&h[i]);for(int i = 1;i<= n;i++)t[i] = min(h[i],t[i-1]+1);//自己一层层消完或前边消完了for(int i = n;i>= 1;i--){t[i] = min(t[i],t[i+1]+1);ans = max(ans,t[i]);}cout<<ans<<endl;return 0;}
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.
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.
Print the number of operations needed to destroy all towers.
62 1 4 6 2 2
3
73 3 3 1 3 3 3
2
The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.
- Bear and Blocks CF-574D(类似dp+思维)
- Codeforces 574D Bear and Blocks【思维】
- cf#318-D - Bear and Blocks-双向dp
- Codeforces Round #318 574D Bear and Blocks(dp)
- codeforces 574D. Bear and Blocks
- 【32.89%】【codeforces 574D】Bear and Blocks
- Codeforces 318 div2.D Bear and Blocks(dp,贪心)
- Codeforces Round #318 D. Bear and Blocks DP
- Codeforces Round #318-(D. Bear and Blocks)
- Codeforces Round #318 D. Bear and Blocks
- Codeforces Round #318 D. Bear and Blocks
- CF Bear and Tree Jumps树形DP
- CF 573B(Bear and Blocks-匹配最长递增序列)
- cf 573B Bear and Blocks 小小的脑洞题
- Codeforces Round #318 (Div. 2) D - Bear and Blocks
- CodeForce #318 div 2 D Bear and Blocks
- codeforces 573B B. Bear and Blocks(线段树+dp)
- CF Bear and Game
- Gcc编译选项大全
- c++中为什么不提倡使用vector<bool>(转)
- class中自身调用方法
- python面向对象
- C++猜数字游戏
- Bear and Blocks CF-574D(类似dp+思维)
- Topological Sorting
- js的类型检测
- C/C++ 撸一段流行的观察者模式
- FL2440
- 树上方法总结 LCA 树上倍增 树链剖分 树的直径 重心
- 表单验证
- nexus配置以及部署在tomcat中
- 各种语言注释标注总结