校内选拔I题题解 构造题 Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) ——D
http://codeforces.com/contest/574/problem/D
Bear and Blocks
1 second
256 megabytes
standard input
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.
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.
6
2 1 4 6 2 2
3
7
3 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.
After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation
题目大意 每次只能消最外层的砖 问多少次能消完
看hint图吧 等价与从右方看 从左到右峰依次为 2 1 4 3 2 1 从左方看 从左到右峰依次为 1 1 2 3 2 2
比较每个位置需要消去的最少次数 依次为 1 1 2 3 2 2的峰
看到这里是不是就明白了呢
我们只需要把山峰等效为 突起 如 1 2 2 3 4 3这样的形式就ok了
具体操作见代码 tw菊苣的dp写法还不是很理解 再研究一下
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
inline void ri(int &num){
num=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<='')num=num*+ch-'',ch=getchar();
num*=f;
}
const int N=1e5+;
int l[N],r[N],a[N];
int main()
{
int n;
ri(n);
for(int i=;i<=n;i++)ri(a[i]);
for(int i=;i<=n;i++) l[i]=min(l[i-]+,a[i]);
for(int i=n;i>=;i--) r[i]=min(r[i+]+,a[i]);
int mx=-;
for(int i=;i<=n;i++) mx=max(mx,min(l[i],r[i]));
printf("%d\n",mx);
return ;
}
AC代码
校内选拔I题题解 构造题 Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) ——D的更多相关文章
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)
以后每做完一场CF,解题报告都写在一起吧 暴力||二分 A - Bear and Elections 题意:有n个候选人,第一个候选人可以贿赂其他人拿到他们的票,问最少要贿赂多少张票第一个人才能赢 ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) B. Bear and Blocks 水题
B. Bear and Blocks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/573/pr ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) A. Bear and Poker 分解
A. Bear and Poker Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/573/pro ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A. Bear and Elections 优先队列
A. Bear and Elections ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B. Bear and Three Musketeers 枚举
B. Bear and Three Musketeers ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)C. Bear and Poker
C. Bear and Poker ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) C. Bear and Drawing
题目链接:http://codeforces.com/contest/573/problem/C题目大意:在两行无限长的点列上面画n个点以及n-1条边使得构成一棵树,并且要求边都在同一平面上且除了节点 ...
- Codeforces Round #609 (Div. 2)前五题题解
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
- BZOJ 3097: Hash Killer I【构造题,思维题】
3097: Hash Killer I Time Limit: 5 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 963 Solved: 36 ...
随机推荐
- 1-2关键字 & 2-1什么是变量
2-1什么是变量 驼峰第一个字母首字母小写后面字母首字母大写 Pascal命名规范:
- Laravel框架之Session操作
//设置session里的值 public function session1(Request $request){ //1.HTTP request session(); /*$request-&g ...
- SqlServer规则
定义:规则时单独的SQLServer对象,可以关联到一个或几个表中的一列或几列.它可以使用多种方式来完成对数据值的校验,可以使用函数返回验证信息,也可以使用关键字BETWEEN,LIKE和IN完成对输 ...
- LeetCode: 521 Longest Uncommon Subsequence I(easy)
题目: anysubsequence of the other strings. A subsequence is a sequence that can be derived from one se ...
- Swift3.0 Set
set的简单的使用方法 //创建一个空set var letters = Set<Character>() //数组字面量创建set,只能存放string var setColors:Se ...
- 豆瓣api获取图片403
1.问题描述 豆瓣的图片资源在网页中不能正常显示,403禁止访问,把地址放到浏览器中就可以正常访问了? 原因是豆瓣现在有防盗链 2.解决问题 在页面中加上 <meta name="re ...
- Unity(2) 脚本简单操作
生命周期(按顺序排列) Awake():脚本唤醒,系统执行的第一个方法,在脚本声明周期内只执行一次,初始化一般可以在这里 Start():Awake之后,Update之前,只执行一次,一般在awake ...
- 后Selenium时代,网页自动化测试用Cypress
本文技术难度★★★,初学自动化测试的朋友慎点!否则会引起焦虑等不适症状,严重者会怀疑自己技术人生! 来自Cypress官网首页! Web开发飞速换代! table控制页面OUT了! 原生态手写网页OU ...
- java并发编程(一)
java并发编程(一) 线程基础 在Java代码中,单独创建线程,都需要使用类java.lang.Thread,通常可以通过集成并扩展Thread的run()方法,也可以来创建一个Thread,将一个 ...
- C 语言实例 - 使用结构体(struct)
C 语言实例 - 使用结构体(struct) C 语言实例 C 语言实例 使用结构体(struct)存储学生信息. 实例 #include <stdio.h> struct student ...