CF 573B
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的更多相关文章
- 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 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- 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 ...
- 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 ...
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
- CF #375 (Div. 2) D. bfs
1.CF #375 (Div. 2) D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...
随机推荐
- Scrapy基础02
一.start_requests def start_requests(self): cls = self.__class__ if method_is_overridden(cls, Spider, ...
- Java面试经典题目合集
32 1.”static”关键字是什么意思?Java中是否可以覆盖(override)一个private或者是static的方法? “static”关键字表明一个成员变量或者是成员方法与类相关,可以在 ...
- Newtonsoft.Json序列化字符串-格式化
转自:https://blog.csdn.net/wlphlj/article/details/51982866最近C#中需要将实体进行json序列化,使用了Newtonsoft.Json publi ...
- JS创建对象之工厂模式
function createPerson(name, age, job) { var o = new Object(); o.name = name; o.age = age; o.job = jo ...
- javascript 正则表达式总结
为什么要使用正则表达式 正则表达式通过由普通字符和特殊字符组成的文字模板完成对字符串的校验,搜索,替换.在javascript中类似这样 /^1\d{10}$/ 复制代码 上面的这个简单的正则用来匹配 ...
- pyqt5-QWidget坐标系统和大小
获取坐标和尺寸: 坐标的获取视频教程:https://v.qq.com/x/page/t085892mzh9.html x() y() 返回控件的坐标 相对于父控件的坐标(窗口框架左上角) ...
- Web前端性能优化常见面试题
一般说来,web前端指网站业务逻辑之前的部分,包括浏览器加载.网站视图模型.图片服务.CDN服务等,主要优化手段有浏览器访问.使用反向代理才.CDN等.1.减少http请求,合理浏览器缓存 2.启用压 ...
- luogu P3295 [SCOI2016]萌萌哒
传送门 题目条件"两个子串\(S[l_1,r_1],S[l_2,r_2]\)完全相同"等价于\(\forall i \in[0,r_1-l_1+1],S_{l1+i}=S_{l_2 ...
- EcustOJ P109跳一跳(离散化+dp)
题目链接 感觉这道题我看了很多天,胡思乱想啊,一开始觉得记忆化搜索会可能T啊,,可能出题人的数据卡的好就稳T了的感觉..后来想了想,好像离散化一下,记一下位置之后再记忆化搜索就应该稳了吧..(好像直接 ...
- vue-CLI踩坑记
vue init webpack vue-demo 使用 windows 7 DOS命令行和gitbash都有选择和实际选择结果不一致的问题, DOS命令行只在 Vue build有问题, gitba ...