CF1373F Network Coverage
对于每一个 \(i\) 可以看作一个管道。赋予三个信息:
- \(\text{minIn}_i\) 表示至少要从上一家 \(i - 1\) 得到连接数,才能正常供给 \(i\) 城市
- \(\text{minOut}_i\) 最坏情况下最少给下一家 \(i + 1\) 多少连接数
- \(\text{maxOut}_i\) 表示最多能给下一家 \(i + 1\) 多少连接数
三个变量维护完毕,我们发现我们可以通过某种方法合并两个相邻的管道,最后剩下一个管道,只需自检查 \(\text{minIn} \le \text{minOut}\) 即可(在最低限度下自我循环传输)。
合并需要分类讨论,假如合并 \(x, y\)。
- 首先必须满足 \(x.maxOut \ge y.minIn\),不然无论何时都满足不了。
- 如果 \(x.minOut \le y.minIn\),那么合并后的最低需求会变大,最大输出量也会被 \(x.maxOut\) 而限制
- 否则,最低输出量会被提高(或不变),最大输出量同样受到限制。
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 1000005;
int n, a[N], b[N];
struct Pipe{
int minIn, minOut, maxOut;
};
Pipe get(int x, int y) {
if (x <= y) return (Pipe) { 0, y - x, y };
else return (Pipe) { x - y, 0, y };
}
Pipe merge(Pipe x, Pipe y) {
if (x.maxOut < y.minIn) return (Pipe) { -1, -1, -1 };
if (x.minOut <= y.minIn) return (Pipe) { x.minIn + y.minIn - x.minOut, y.minOut, min(y.maxOut, y.minOut + x.maxOut - y.minIn) };
else return (Pipe) { x.minIn, min(y.maxOut, y.minOut + x.minOut - y.minIn), min(y.maxOut, y.minOut + x.maxOut - y.minIn) };
}
int main() {
int T; scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
for (int i = 1; i <= n; i++) scanf("%d", b + i);
Pipe cur = get(a[1], b[1]);
bool ok = true;
for (int i = 2; i <= n; i++) {
cur = merge(cur, get(a[i], b[i]));
if (cur.minIn == -1) { ok = false; break; }
}
if (cur.minOut < cur.minIn) ok = false;
puts(ok ? "YES" : "NO");
}
return 0;
}
CF1373F Network Coverage的更多相关文章
- Codeforces 1373F - Network Coverage(模拟网络流)
Codeforces 题面传送门 & 洛谷题面传送门 提供一个模拟网络流的题解. 首先我们觉得这题一脸可以流的样子,稍微想想可以想到如下建图模型: 建立源点 \(S,T\) 和上下两排点,不妨 ...
- AAU
AAU (Active Antenna Unit) In the MBB (Mobile Broadband) era, the astonishing growth in data traffic ...
- hdu-5681 zxa and wifi(dp)
题目链接: zxa and wifi Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- ARVE: Augmented Reality Applications in Vehicle to Edge Networks
ARVE:车辆到边缘网中的增强现实应用 本文为SIGCOMM 2018 Workshop (Mobile Edge Communications, MECOMM)论文. 笔者翻译了该论文.由于时间仓促 ...
- On the way to the park Gym - 101147I 几何
http://codeforces.com/gym/101147/problem/I I. On the way to the park time limit per test 5 seconds m ...
- android NDK 神经网络API——是给tensorflow lite调用的底层API,应用开发者使用tensorflow lite即可
eural Networks API In this document show more Understanding the Neural Networks API Runtime Neural N ...
- 哈理工2015暑假训练赛 zoj 2078Phone Cell
Phone CellTime Limit:10000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu SubmitStatus ...
- Smart internet of things services
A method and apparatus enable Internet of Things (IoT) services based on a SMART IoT architecture by ...
- 【论文速读】Fangfang Wang_CVPR2018_Geometry-Aware Scene Text Detection With Instance Transformation Network
Han Hu--[ICCV2017]WordSup_Exploiting Word Annotations for Character based Text Detection 作者和代码 caffe ...
随机推荐
- 1-03 Java的基本程序设计结构
1-03 Java的基本程序设计结构 3.1 & 3.2 在一个单词中间使用大写字母的方式称为骆驼命名法.以其自身为例,应该写成CamelCase). 与C/C++一样,关键字void表示这个 ...
- 《HarmonyOS设备开发入门手册》
HarmonyOS设备开发入门手册-更新 [欢迎大家点击下载] 作者:连志安 想了解更多内容,请访问: 51CTO和华为官方战略合作共建的鸿蒙技术社区 https://harmonyos.51cto. ...
- java 打包压缩包下载文件
1. 下载压缩包zip方法 @Override public void downloadZip(HttpServletResponse servletResponse) { String nowTim ...
- 关于mybatisPlus一些坑,当条件为null时
1.TStaffDepart 属性有值是才匹配条件,会报错,相当于mybatis if 判断 eg:TStaffDepart staffDepart = new TStaffDepart();staf ...
- Hive 报错 Failed to load class "org.slf4j.impl.StaticLoggerBinder".
打开hive报错 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaultin ...
- matlab 第五章单元数组、字符串作业
1.创建 2×2 单元数组,第 1.2 个元素为字符串,第三个元素为整型变量,第四个元素为双精度(double)类型,并将其用图形表示. A=cell(2,2); A(1,1)={'mat'}; A( ...
- 解决Ubuntu配置nginx出现的问题
Ubuntu18.04配置nginx出现的各种错误 缺少pcre库 编译nginx 出现错误 安装pcre库,出现错误 手动编译安装pcre库 (1)下载并解压pcre库 wget https://f ...
- vue中使用transition和animate.css动画效果
一.单个动画中,使用div中引用animate动画 1.下载依赖 npm install animate.css –save 2.main.js中全局引用 import animate from 'a ...
- FL Studio 插件使用技巧——Fruity Reeverb 2(下)
了解大教堂声场的特点 上节教程中我们说到,混响具有营造空间感的作用.当我们想要在FL Studio软件中用Fruity Reeverb 2 插件有目标地模仿一个特定空间的环境时,我们需要充分了解该空间 ...
- 理解与使用Treiber Stack
目录 背景 名称由来 CompletableFuture源码实现 FutureTask实现 Treiber Stack抽象实现 入栈 出栈 示例 参考 背景 最近在很多JDK源码中都看到了Treibe ...