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 ...
随机推荐
- 1.6-1.7 定义agent 读取日志存入hdfs
一.定义agent,并运行 1.配置文件 #计划 ##收集hive的日志,存到hdfs /opt/cdh-5.3.6/hive-0.13.1-cdh5.3.6/logs/hive.log 命令:tai ...
- lightoj 1078【同余定理】
题意: 给你一个n和一个数 digit ,问你最少需要多少个 digit 使得整除于n; 思路: 同余定理(a+b)%n=(a%n+b%n)%n; (m%n+m%n*10+m%n*100+m%n*10 ...
- 51nod1010【二分】
打表+二分 #include <bits/stdc++.h> using namespace std; typedef long long LL; const LL inf=1e18+10 ...
- 即时通讯新手入门:一文读懂什么是Nginx?它能否实现IM的负载均衡?
本文引用了“蔷薇Nina”的“Nginx 相关介绍(Nginx是什么?能干嘛?)”一文部分内容,感谢作者的无私分享. 1.引言 Nginx(及其衍生产品)是目前被大量使用的服务端反向代理和负载均衡 ...
- IDEA快捷的添加包名
Intellij IDEA使用(十四)—— 在IDEA中创建包(package)的问题 2018年02月24日 17:24:49 _云卷云舒_ 阅读数:6264 标签: intellij idea 更 ...
- Unrecogized font family ‘Ionicons’ 在ios上报错,android正常
解决方法: react-native link react-native-vector-icons 很多模块都需要link一下
- JSP | 基础 | 中文字符的传递
设置传递格式: request.setCharacterEncoding("utf-8"); 中文字符解码: import java.net.URLDecoder; String ...
- C# 常量与只读属性的区别
public readonly string name ----这个name是个只读属性,不需要在定义时初始化值,而是可以在构造函数中完成初始化. public const int age =18 ...
- BZOJ1053(数学结论进行剪枝搜索)
Description 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4.如果某个正整数x满足:g(x)>g(i) 0<i<x,则称x为反质数.例如,整数1 ...
- 用注解@DelcareParents实现引用增强
引用增强,是一个比较特殊的增强,不同于其他方法级别的增强. 引用增强可以实现:一个Java类,没有实现A接口,在不修改Java类的的情况下,使其具备A接口的功能. 先看看背景,我们有个Love接口: ...