Codeforces Round #318 574D Bear and Blocks(dp)

CrewAI 多 Agent 实战包 v1(Mock免Key跑通+通义千问可选+流水线样例) 本资源是 CrewAI 风格多 Agent 可运行工程包:研究→写作→审校等流水线样例。无 API Key 时自动降级 Mock 引擎跑通;有 DASHSCOPE_API_KEY 时可接真实 CrewAI + 通义千问。含中文 README、samples、smoke 留档、单元测试。本包不含密钥。关联博客:https://blog.youkuaiyun.com/mtl1994 立即下载

D. 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.

Sample test(s)
input
6
2 1 4 6 2 2
output
3
input
7
3 3 3 1 3 3 3
output
2
Note

The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.

After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation.


看了别人代码才知道是dp,没学过的dp类型。。


AC代码:


#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
const int MAXN = 1e5 + 5;
int a[MAXN], b[MAXN], n, l, ans;
int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) 
		scanf("%d", &a[i]);
	for(int i = 1; i <= n; ++i) {
		l = min(l, a[i] - i);
		b[i] = l + i;
	}
	l = n + 1;
	for(int i = n; i >= 1; --i) {
		l = min(l, a[i] + i);
		b[i] = min(b[i], l - i);
	}
	for(int i = 1; i <= n; ++i)
		ans = max(ans, b[i]);
	printf("%d\n", ans);
	return 0;
}


市场销售总监年终汇报必备PPT.pptx 市场销售总监年终汇报必备PPT 立即下载

相关推荐

无人机通信安全渗透测试:从信号拦截到GPS欺骗的完整攻防框架

在物联网和智能设备普及的背景下,无线通信安全成为关键基础设施防护的核心环节。其原理在于,通过软件定义无线电等设备对空中的射频信号进行捕获、分析与模拟,从而评估通信协议在加密、认证和防重放等方面的脆弱性。这项技术的价值在于,它能主动发现并修复系统设计缺陷,避免因信号被拦截或欺骗导致设备被劫持、数据泄露等重大安全事件。其应用场景广泛,涵盖消费电子、工业控制及关键基础设施等领域。本文聚焦于无人机这一典型移动物联网终端,深入探讨如何构建一套针对其通信链路的渗透测试方法论,其中涉及信号拦截、协议逆向等关键技术,旨在为

weixin_34128237的博客 391

【矩阵相关】[Codeforces - 736D]Permutations

题目大意 n个的排列,给你m条规则,规则是一个数对(ai,bi)(a_i,b_i),代表数字bib_i可以放在第aia_i个位置。 对于每一条规则,如果我们删掉它,符合剩下的规则的排列数如果是奇数,就输出YES,否则输出NO。 分析 首先,我们可以把这些规则表示成邻接矩阵。 那本来的排列数就是邻接矩阵的积和式,但是我们无法快速计算积和式,但是我们只需要知道奇偶性。 考虑一下求积和式

LiuJunhao's Blog 1211

SAP BSP网页开发入门:从SE80创建到MVC实战(附成品展示)

本文详细介绍了SAP BSP网页开发的入门与实战,从SE80环境搭建到MVC架构实现的全流程。通过具体案例和代码示例,帮助开发者掌握业务服务器页面(BSP)技术,提升SAP Web化转型中的开发效率,适用于需要扩展SAP功能的企业场景。

x1y2z的博客 1万+

Bear and Elections CodeForces - 574A(优先队列)

C - Bear and Elections CodeForces - 574A Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candida

codeswarrior的博客 479

PX4 EKF2协方差矩阵‘负定’了怎么办?保姆级排查与数值稳定性修复指南

本文深入解析PX4 EKF2协方差矩阵出现‘负定’问题的原因,并提供全面的排查与修复方案。从理论分析到实践操作,详细介绍了数值稳定性危机的诊断工具、算法加固措施及工程实践中的防御性编程技巧,帮助飞控工程师有效解决滤波算法中的数值稳定性问题。

weixin_28730927的博客 319

几率大的网络安全面试题(含答案)

其他篇章:Java校招极大几率出的面试题(含答案)----汇总 本文面试题汇总: 防范常见的 Web 攻击 重要协议分布层 arp协议的工作原理 rip协议是什么?rip的工作原理 什么是RARP?工作原理 OSPF协议?OSPF的工作原理 TCP与UDP区别总结 什么是三次握手四次挥手? tcp为什么要三次握手? dns是什么?dns的工作原理 一次完整的HTTP请求过程 Cookies和ses...

睶 6万+

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)——Ddp——Bear and Blocks

http://codeforces.com/contest/574/problem/D /* 容易得到状态方程 dp[i] = min(a[i], dp[i-1]+1,dp[i-2]+2 ....dp[i+1]+1,,,) 那么可以得到两个递推式 dp[i] = min(a[i], 之间的min+1) dp[i] = min(a[i], dp[i], 之后的min+1) ...

dgjm4087的博客 193

高通 Gen AI 推理扩展 (GENIE)(5):实战指南与Engine API深度解析

本文深入解析高通Gen AI推理扩展(GENIE)的Engine API核心功能与实战应用,涵盖引擎实例化、多引擎动态切换、性能调优及跨平台部署等关键技巧。通过详细代码示例和性能数据,帮助开发者高效利用GENIE进行AI推理,提升应用性能与稳定性。

weixin_29065959的博客 464

Codeforces Round #321 (Div. 2) 580C Kefa and Park(dfs)

题目链接: 第一行给你n、m,接下来的一行有n个数,如果为1则代表这个点有cat,接下来的n-1行每行给出x、y,表示x、y相连。问你从1出发 能到达的叶子结点有几个,要求到达叶子结点的路上连续有cat的点不超过m。 a数组保存结点是否含有cat,从1这个点开始dfs,每次dfs对cat数组操作,记录连续的含有cat的点数,回溯时再判断当前结点是否满足 条件,要求结点为叶子

GKHack's Blog 2041

阿里开源最强数字人工具 EchoMimicV2,本地部署(一)

EchoMimicV2是阿里推出的半身人体AI数字人项目,基于参考图片、音频剪辑和手部姿势序列生成高质量动画视频,确保音频内容与半身动作的一致性。现在本地部署,安装体验一下。

缘分天空的专栏 4614

ICC II 时钟树综合(CTS)前奏:从约束定义到NDR规则的全方位设置指南

本文详细介绍了ICC II中时钟树综合(CTS)的前期准备工作,包括约束定义、NDR规则设置和时钟平衡点控制等关键步骤。通过实际案例和代码示例,指导工程师如何优化时钟偏斜、插入延迟和信号质量,确保芯片设计的时序收敛和性能稳定。特别强调了非默认布线规则(NDR)在时钟网络设计中的重要性。

weixin_42530458的博客 212

Codeforces Round #200 (Div. 2)344E Read Time(二分)

E. Read Time time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mad scientist Mike does not use slow hard disks

GKHack's Blog 1749

Vue2 - 最新详细实现接入天地图详细配置流程及示例代码教程,提供获取用户当前定位的城市名称及省市区数据、精准经纬度信息、IP属地定位、地图搜索标点等示例,解决天地图跨域报错/页面白屏/定位不准问题

vue2,nuxt2,天地图,使用教程,vue接入国家天地图,定位api,ip属地定位,获取用户当前位置数据,省市区,地图不显示,白屏,报错,vue2如何使用天地图,地图选点,cors跨域,白名单设置了还是不行,vue项目调用天地图api实现定位,Vue2中使用天地图,详细教程,天地图申请密钥key教程,经纬度,经纬度不准确,一直定位北京,定位在北京不准怎么办,nuxt项目天地图,网站,网页,h5页面,地图显示不全,获取当前定位,如何使用天地图,拿到客户ip地址定位城市名称,距离计算,实时搜索地址逆解析,天

🏆 前端领域优质创作者 5325

Codeforces Round #325 (Div. 2) 586ABC题解

题目链接:点击打开链接 A: 给出Alena的课表, 1代表有课, 0代表没课, 2个连续0以上可以回家休息, 问你一天在学校待多久. 直接模拟即可, 可以直接计算1, 101的数目. 我记录了开头的1和结尾的1, 然后减去2个连续0以上的个数就是答案. AC代码: #include "iostream" #include "cstdio" #include "cstring" #

GKHack's Blog 1711

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Codeforces Round #308 (Div. 2)题解

第二天补的 并不都是自己写的 参考了别人的题解 感觉这次cf题意好懂 就是做起来嘛。。 毕竟我还太弱。。 只为落实 A. Vanya and Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input

GKHack's Blog 1674

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Codeforces Round #322 (Div. 2) 581A 581B 581C

581A链接:点击打开链接 给你a只红袜子,b只蓝袜子,问你可以组成多少对颜色不同的袜子以及剩下多少对单色袜子。 小小的脑洞,答案分别为a, b最小值以及a - b绝对值的一半。 AC代码: #include "iostream" #include "cstdio" #include "cstring" #include "algorithm" using na

GKHack's Blog 1665

Codeforces Round #250 (Div. 2) 437C The Child and Toy(脑洞贪心)

C. The Child and Toy time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output On Children's Day, the child got a toy

GKHack's Blog 1626

Codeforces Round #313 (Div. 2) 560D Equivalent Strings(dos)

D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today on a lecture about strings Gera

GKHack's Blog 1616

Codeforces Round #315 (Div. 2)569C Primes or Palindromes?(预处理)

C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that t

GKHack's Blog 1599

Codeforces Round #201 (Div. 2) 347C Alice and Bob(脑洞)

C. Alice and Bob time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It is so boring in the summer holiday, isn

GKHack's Blog 1584

Manthan, Codefest 16 633C Spy Syndrome 2(dfs + stl)

C. Spy Syndrome 2 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After observing the results of Spy Syndro

GKHack's Blog 1574

Codeforces Round #337 (Div. 2) 610D Vika and Segments(线段树)

D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vika has an infinite sheet of squared

GKHack's Blog 1531

Codeforces Round #250 (Div. 2) 437A The Child and Homework(模拟)

A. The Child and Homework time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Once upon a time a child got a tes

GKHack's Blog 1504

Codeforces Round #315 (Div. 2)569D Symmetric and Transitive(dp)

D. Symmetric and Transitive time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Little Johnny has recently le

GKHack's Blog 1501

Codeforces Round #Pi (Div. 2)567A Lineland Mail(模拟)

A. Lineland Mail time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output All cities of Lineland are located on the

GKHack's Blog 1485

Codeforces Round #332 (Div. 2) 599C Day at the Beach(脑洞)

C. Day at the Beach time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Squidward, Spongebob and Patric

GKHack's Blog 1454
上一篇: Codeforces Round #318 574B Bear and Three Musketeers(模拟)
下一篇: BestCoder Round #53 (div.2) HDOJ5422 Rikka with Graph(floyd)
GKHack
博客等级 码龄11年 48粉丝 291原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值