不难发现在一次操作以后,hi=min(hi-1,hi-1,hi+1),迭代这个式子得到k次操作以后hi=min(hi-j-(k-j),hi-k,hi+j-(k-j)),j = 1,2,3...

当k == min(hi-j+j,hi+j+j)时hi会变成0,因为min具有传递性,那么可以左右分开来考虑,hi-j+j化一下就是hi-j-(i-j)+i,其中后面i和j无关,所以只要找出前面最小的hi-i

对于右边的类似处理,最后再扫一遍,得出最大的一个k就是答案。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+;
int n;
int h[maxn];
int k[maxn]; int main()
{
scanf("%d",&n);
for(int i = ; i <= n; i++) scanf("%d",h+i); int cnt = ;
for(int i = ; i <= n; i++){
cnt = min(cnt,h[i]-i);
k[i] = i + cnt;
}
cnt = n+;
for(int i = n; i >= ; i--){
cnt = min(cnt,h[i]+i);
k[i] = min(k[i],cnt-i);
}
int ans = ;
for(int i = ; i <= n; i++){
ans = max(ans,k[i]);
}
printf("%d\n",ans);
return ;
}

Codeforces Round #318 (Div. 2) D Bear and Blocks (数学)的更多相关文章

  1. Codeforces Round #318 (Div. 2) B Bear and Three Musketeers (暴力)

    算一下复杂度.发现可以直接暴.对于u枚举a和b,判断一下是否连边,更新答案. #include<bits/stdc++.h> using namespace std; int n,m; ; ...

  2. Codeforces Round #318 (Div. 2) A Bear and Elections (优先队列模拟,水题)

    优先队列模拟一下就好. #include<bits/stdc++.h> using namespace std; priority_queue<int>q; int main( ...

  3. Codeforces Round #318 (Div. 2) C Bear and Poker (数学)

    简单题,求一下所有数的2和3的幂是任意调整的,把2和3的因子除掉以后必须相等. 求lcm,爆了long long.我得好好反省一下,对连乘不敏感 #include<bits/stdc++.h&g ...

  4. Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)

    Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...

  5. Codeforces Round #622 (Div. 2) B. Different Rules(数学)

    Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...

  6. Codeforces Round #318(Div 1) 573A, 573B,573C

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 这场的前两题完全是手速题...A题写了7分钟,交的时候已经500+了,好在B题出的 ...

  7. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #356 (Div. 2) C. Bear and Prime 100(转)

    C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)

    B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

随机推荐

  1. 1.6-1.10 使用Sqoop导入数据到HDFS及一些设置

    一.导数据 1.import和export Sqoop可以在HDFS/Hive和关系型数据库之间进行数据的导入导出,其中主要使用了import和export这两个工具.这两个工具非常强大, 提供了很多 ...

  2. Ubuntu18.04安装和配置Java JDK11并卸载自带OpenJDK

    卸载自带的OpenJDK方法: 在终端执行命令:sudo apt-get remove openjdk* Ubuntu18.04安装JDK11.0.2 前面步骤一样,可参考:https://www.c ...

  3. __doPostBack方法解析 __VIEWSTATE __EVENTTARGET __doPostBack __EVENTARGUMENT

    关于这个的另一篇博客:http://www.cnblogs.com/Silicon-Fado/archive/2009/04/21/1440437.html __VIEWSTATE:页面状态信息在客户 ...

  4. PhpStorm插件之CodeGlance

    安装插件 File->Setting->Pluugins   搜索  CodeGlance 如何使用 安装完插件后,RESTART IDE,随便打开一个文件都可看到效果

  5. 483. Smallest Good Base

    For an integer n, we call k>=2 a good base of n, if all digits of n base k are 1. Now given a str ...

  6. lightoj1006【记忆化搜索(我是这么叫)】

    搜索的时候记录一下,注意要long long: #include<cstdio> #include<queue> #include<map> #include< ...

  7. lightoj1001【简单题】

    题意: 一个人的值不能超过10: #include<stdio.h> #include<queue> #include<string.h> #include< ...

  8. HDU4247【瞎搞】

    题意: 给你4个小正方形的边长,让你求一个最小大正方形的边长以至于可以存这么四个正方形. 思路: 比划了一下...就是最大边+次大边,因为他们一定有交集. #include <cstdio> ...

  9. oracle的日期数据类型

    https://blog.csdn.net/qq_33573235/article/details/78154928(转)

  10. unity常用插件

    Unity3D常用插件,网址:http://jingyan.baidu.com/article/7f766daf4ef2844100e1d079.html ,想想自己也有小半年unity经验了,于是整 ...