Codeforces Round #318 (Div. 2) D Bear and Blocks (数学)
不难发现在一次操作以后,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 (数学)的更多相关文章
- Codeforces Round #318 (Div. 2) B Bear and Three Musketeers (暴力)
算一下复杂度.发现可以直接暴.对于u枚举a和b,判断一下是否连边,更新答案. #include<bits/stdc++.h> using namespace std; int n,m; ; ...
- Codeforces Round #318 (Div. 2) A Bear and Elections (优先队列模拟,水题)
优先队列模拟一下就好. #include<bits/stdc++.h> using namespace std; priority_queue<int>q; int main( ...
- Codeforces Round #318 (Div. 2) C Bear and Poker (数学)
简单题,求一下所有数的2和3的幂是任意调整的,把2和3的因子除掉以后必须相等. 求lcm,爆了long long.我得好好反省一下,对连乘不敏感 #include<bits/stdc++.h&g ...
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...
- Codeforces Round #622 (Div. 2) B. Different Rules(数学)
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...
- Codeforces Round #318(Div 1) 573A, 573B,573C
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 这场的前两题完全是手速题...A题写了7分钟,交的时候已经500+了,好在B题出的 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 5、overflow、hover
一.overflow 1.属性介绍 说明: 这个属性定义溢出元素内容区的内容会如何处理.如果值为 scroll,不论是否需要,用户代理都会提供一种滚动机制.因此,有可能即使元素框中可以放下所有内容也会 ...
- lua基本语法
1.注释-- ; --[[ ]] 2.控制语句: if ..then .. elseif.. then.. else.. end while.. do..end repeat ..u ...
- C/C++内存检测工具Valgrind
内存检测Valgrind简介 Valgrind是运行在Linux上一套基于仿真技术的程序调试和分析工具,作者是获得过Google-O'Reilly开源大奖的Julian Seward, 它包含一个内核 ...
- studio 配置 opencv3.1
环境 win10 android studio2.0 OpenCV-3.1.0-android-sdk android-ndk-r10e-windows-x86_64 jdk-8u102-window ...
- [Xcode 实际操作]九、实用进阶-(8)实现App的Setting设置:添加和读取程序的配置信息
目录:[Swift]Xcode实际操作 本文将演示如何实现添加和读取程序的配置信息. 在项目文件夹[DemoApp]上点击鼠标右键->[New File]创建一个设置束文件 ->[Sett ...
- rpm、yum(转)
rpm http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/10/08/2203153.html yum http://www.cnblogs ...
- Java 执行linux命令(转)
转自 http://blog.csdn.net/a19881029/article/details/8063758 java程序中要执行linux命令主要依赖2个类:Process和Runtime 首 ...
- 两句话跳转QQ聊天界面 通过web方式
NSString *qq=[NSString stringWithFormat:"]; NSURL *url2 = [NSURL URLWithString:qq]; if ([[UIApp ...
- ERROR: Could not connect to lockdownd, error code -19 -20
执行命令行 brew install libimobiledevice --HEAD
- [洛谷3935]Calculating
题目链接:https://www.luogu.org/problemnew/show/P3935 首先显然有\(\sum\limits_{i=l}^rf(i)=\sum\limits_{i=1}^rf ...