CF 573B
来源:互联网 发布:windows xp 下载 编辑:程序博客网 时间:2024/06/06 07:52
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 + 7;int Num[maxn];int Dp[maxn];int Dp2[maxn];set<int> S;int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for(int i = 1; i <= n; ++i) { //int t; cin >> Num[i]; } for(int i = 1; i <= n; ++i) Dp[i] = min(Dp[i-1]+1,Num[i]); for(int i = n; i >= 1; i--) Dp2[i] = min(Dp2[i+1]+1,Num[i]); int ans = 0; for(int i = 1; i <= n; ++i) ans = max(ans, min(Dp[i],Dp2[i])); cout << ans << endl;}
- CF 573B DP
- CF 573B
- cf-B
- cf B
- CF 1B Spreadsheet
- CF 3B Lorry
- CF 176B
- CF 91B
- cf 131 DIV2 B
- CF 113B || CF196D
- CF 126B
- CF-236B
- CF 254B(日期)
- cf 79B
- CF - 158B - Taxi
- CF 296B
- CF 173(div2) B
- cf:B-QR code
- UVA 1151
- Java的poi技术读取和导入Excel
- CF 2B The least round way DP+Math
- POJ 1659
- HDU 4549
- CF 573B
- 在Eclipse中导入SVN库里的Maven项目
- 在网上看到好代码 ,记得发表到网上
- LA 4108 (线段树)
- java抽象类与接口的区别(谈谈自己的理解)
- iOS开发:创建真机调试证书
- CF 189A Cut Ribbon
- opencv 轮廓查找 findContours
- CF 489C 暴力处理