[CF954G]Castle Defense
题目大意:有$n$个点,每个点最开始有$a_i$个弓箭手,在第$i$个位置的弓箭手可以给$[i-r,i+r]$区间加上$1$的防御,你还有$k$个弓箭手,要求你最大化最小防御值
题解:二分答案,从右向左扫,显然得知,给一个位置增加防御值最好方式是在最右段加一些弓箭手。
卡点:无
C++ Code:
- #include <cstdio>
- #define maxn 500010
- const long long inf = 0x3f3f3f3f3f3f3f3f;
- int n, R;
- long long k, protect1[maxn], s[maxn], protect2[maxn], protect3[maxn], p[maxn], protect4[maxn];
- inline int min(int a, int b) {return a < b ? a : b;}
- inline bool check(long long mid) {
- __builtin_memset(p, 0, sizeof p);
- int l = -R, r = R;
- long long now = 0, K = k;
- for (int i = 0; i < r; i++) now += s[i];
- for (int i = 0; i < n; i++) {
- now += s[r], now -= s[l - 1] + p[l - 1];
- if (now < mid) {
- p[r] = mid - now;
- K -= p[r];
- if (K < 0) return false;
- now = mid;
- }
- r++, l++;
- }
- return true;
- }
- int main() {
- scanf("%d%d%lld", &n, &R, &k);
- for (int i = 0; i < n; i++) scanf("%lld", s + i);
- long long l = 0, r = inf, ans;
- while (l <= r) {
- long long mid = l + r >> 1;
- if (check(mid)) {
- l = mid + 1;
- ans = mid;
- } else r = mid - 1;
- }
- printf("%lld\n", ans);
- return 0;
- }
[CF954G]Castle Defense的更多相关文章
- Educational Codeforces Round 40 G. Castle Defense (二分+滑动数组+greedy)
G. Castle Defense time limit per test 1.5 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 954 G. Castle Defense
http://codeforces.com/problemset/problem/954/G 二分答案 检验的时候,从前往后枚举,如果发现某个位置的防御力<二分的值,那么新加的位置肯定是越靠后越 ...
- [CodeForces954G]Castle Defense(二分答案+差分)
Description 题目链接 Solution 二分答案,套一个差分标记即可 每次放弓箭手显然越右边越优 Code #include <cstdio> #include <alg ...
- Educational Codeforces Round 40 (Rated for Div. 2) 954G G. Castle Defense
题 OvO http://codeforces.com/contest/954/problem/G 解 二分答案, 对于每个二分的答案值 ANS,判断这个答案是否可行. 记 s 数组为题目中描述的 a ...
- Educational Codeforces Round 40 (Rated for Div. 2) Solution
从这里开始 小结 题目列表 Problem A Diagonal Walking Problem B String Typing Problem C Matrix Walk Problem D Fig ...
- Educational Codeforces Round 40 A B C D E G
A. Diagonal Walking 题意 将一个序列中所有的\('RU'\)或者\('UR'\)替换成\('D'\),问最终得到的序列最短长度为多少. 思路 贪心 Code #include &l ...
- Castle Core 4.0.0 alpha001发布
时隔一年多以后Castle 项目又开始活跃,最近刚发布了Castle Core 4.0.0 的alpha版本, https://github.com/castleproject/Core/releas ...
- 对Castle Windsor的Resolve方法的解析时new对象的探讨
依赖注入框架Castle Windsor从容器里解析一个实例时(也就是调用Resolve方法),是通过调用待解析对象的构造函数new一个对象并返回,那么问题是:它是调用哪个构造函数呢? 无参的构造函数 ...
- AOP之Castle DynamicProxy 动态代理
这里主要介绍使用castle这个动态代理,在.net一些开源的框架里可以找到它的影子,就连微软的rchard也是使用这个进行方法拦截等可以基于这个进行方法拦截,在这个方面PostSharp算是比较好用 ...
随机推荐
- 使用winsw将spring-boot jar包注册成windows服务
背景:最近的项目中使用spring-boot, https://github.com/kohsuke/winsw/releases <service> <id>YJPSS< ...
- Vscode插件--微信小程序格式化以及高亮组件wxml-vscode
wxml-vscode wxml-vscode 仓库 提问题 安装 通过 F1 或者 CMD + Shift + P 输入 install. 选择: Install Extension. 特性 格式化 ...
- Codeforces#498F. Xor-Paths(折半搜索)
time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standa ...
- 配置intellij idea中的欢迎页而不使用默认的index.jsp
在web.xml中添加 <welcome-file-list> <welcome-file>abc.jsp</welcome-file> </welcome- ...
- Thymeleaf显示Map集合数据
<select class="form-control zz-set-input-size" id="channel"> <option va ...
- 对Neural Machine Translation by Jointly Learning to Align and Translate论文的详解
读论文 Neural Machine Translation by Jointly Learning to Align and Translate 这个论文是在NLP中第一个使用attention机制 ...
- linxu信号种类
使用kill -l 命令,可看到linux支持的信号列表: 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGB ...
- POJ:3684-Physics Experiment(弹性碰撞)
Physics Experiment Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3392 Accepted: 1177 Sp ...
- POJ:1995-Raising Modulo Numbers(快速幂)
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 9512 Accepted: 578 ...
- 初见spark-04(高级算子)
今天,这个是spark的高级算子的讲解的最后一个章节,今天我们来介绍几个简单的算子, countByKey val rdd1 = sc.parallelize(List(("a", ...