CF1561C Deep Down Below 题解
CF1561C Deep Down Below 题解
- 题目
- 链接
- 字面描述
- Deep Down Below
- 题面翻译
- 题目描述
- 输入格式
- 输出格式
- 样例 #1
- 样例输入 #1
- 样例输出 #1
- 提示
- 思路
- TLE算法
- 具体思想
- TLE特例
- AC思想
- 代码实现
- 备注
题目
链接
https://www.luogu.com.cn/problem/CF1561C
字面描述
Deep Down Below
题面翻译
TTT 组数据,每次给定 nnn 个任务,第 iii 个任务给定 kik_iki 个怪物,每个怪物有一个能力值 ai,ja_{i,j}ai,j 你要按顺序把这 kik_iki 个怪物杀死,你能杀死一个怪物当且仅当你的能力值严格大于怪物的能力值,杀死一个怪物后,你的能力值将会 +1+1+1。
你可以按任意顺序完成这 nnn 个任务,你需要确定最小的初始能力值。
T≤105,n≤105,ki≤105,∑ki≤105,ai,j≤109T\leq 10^5,n\leq 10^5,k_i\leq10^5,\sum k_i\leq 10^5,a_{i,j}\leq 10^9T≤105,n≤105,ki≤105,∑ki≤105,ai,j≤109。
题目描述
In a certain video game, the player controls a hero characterized by a single integer value: power. The hero will have to beat monsters that are also characterized by a single integer value: armor.
On the current level, the hero is facing $ n $ caves. To pass the level, the hero must enter all the caves in some order, each cave exactly once, and exit every cave safe and sound. When the hero enters cave $ i $ , he will have to fight $ k_i $ monsters in a row: first a monster with armor $ a_{i, 1} $ , then a monster with armor $ a_{i, 2} $ and so on, finally, a monster with armor $ a_{i, k_i} $ .
The hero can beat a monster if and only if the hero’s power is strictly greater than the monster’s armor. If the hero can’t beat the monster he’s fighting, the game ends and the player loses. Note that once the hero enters a cave, he can’t exit it before he fights all the monsters in it, strictly in the given order.
Each time the hero beats a monster, the hero’s power increases by $ 1 $ .
Find the smallest possible power the hero must start the level with to be able to enter all the caves in some order and beat all the monsters.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 10^5 $ ). Description of the test cases follows.
The first line of each test case contains a single integer $ n $ ( $ 1 \le n \le 10^5 $ ) — the number of caves.
The $ i $ -th of the next $ n $ lines contains an integer $ k_i $ ( $ 1 \le k_i \le 10^5 $ ) — the number of monsters in the $ i $ -th cave, followed by $ k_i $ integers $ a_{i, 1}, a_{i, 2}, \ldots, a_{i, k_i} $ ( $ 1 \le a_{i, j} \le 10^9 $ ) — armor levels of the monsters in cave $ i $ in order the hero has to fight them.
It is guaranteed that the sum of $ k_i $ over all test cases does not exceed $ 10^5 $ .
输出格式
For each test case print a single integer — the smallest possible power the hero must start the level with to be able to enter all the caves in some order and beat all the monsters.
样例 #1
样例输入 #1
2
1
1 42
2
3 10 15 8
2 12 11
样例输出 #1
43
13
提示
In the first test case, the hero has to beat a single monster with armor $ 42 $ , it’s enough to have power $ 43 $ to achieve that.
In the second test case, the hero can pass the level with initial power $ 13 $ as follows:
- enter cave $ 2 $ :
- beat a monster with armor $ 12 $ , power increases to $ 14 $ ;
- beat a monster with armor $ 11 $ , power increases to $ 15 $ ;
- enter cave $ 1 $ :
- beat a monster with armor $ 10 $ , power increases to $ 16 $ ;
- beat a monster with armor $ 15 $ , power increases to $ 17 $ ;
- beat a monster with armor $ 8 $ , power increases to $ 18 $ .
思路
TLE算法
具体思想
本人最初的想法十分的朴素,针对nnn个任务维护nnn个队首指针。
- 每次比较出nnn个任务队首怪兽的最小值
- 与当前预算的能力值比较是否能继续打怪,是 -> 继续 ,否 -> 加到怪兽能力值+1即可。
TLE特例
如果有1e5个任务,每个任务只有1个怪兽。
按此算法:
时间复杂度退化:O(n⋅Σk)≈1e10O(n·Σk)≈1e10O(n⋅Σk)≈1e10 TLE ! ! !
AC思想
2阶段处理
- 算出每组打怪加能力的情况下每一个怪兽所对应初始能力值,并取max
- 将nnn个max从小到大排序,依次循环,看每个max加上对应任务里的元素数(能加多少次能力),是否能满足下一个max,是 -> continue ,否 -> 加到下一个max。
时间复杂度:O(Σk⋅log(Σk))≈2e6O(Σk·log(Σk))≈2e6O(Σk⋅log(Σk))≈2e6
阶段线性处理,tql !
代码实现
#include<bits/stdc++.h>
using namespace std;const int maxn=1e5+10;
int t,n,ans;
int k[maxn];
vector<int>e[maxn];
struct node{int v,cnt;
}a[maxn];
inline bool cmp(node p,node q){return p.v<q.v;}
int main(){scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=1;i<=n;i++){e[i].clear();scanf("%d",&k[i]);//算每组的最大值for(int j=1;j<=k[i];j++){int x;scanf("%d",&x);x=x+2-j;if(j!=1)x=max(x,e[i][j-2]);e[i].push_back(x);}a[i].v=e[i][k[i]-1];//最大值的最小取值a[i].cnt=k[i];//任务里的怪兽数//printf("%d = %d %d\n",i,a[i].v,a[i].cnt);}sort(a+1,a+n+1,cmp);ans=a[1].v;int l=ans+a[1].cnt;//排序比较for(int i=2;i<=n;i++){if(l<a[i].v){ans=ans+a[i].v-l;l=a[i].v;}l+=a[i].cnt;}printf("%d\n",ans);}return 0;
}
备注
写入好题本
相关文章:
CF1561C Deep Down Below 题解
CF1561C Deep Down Below 题解题目链接字面描述Deep Down Below题面翻译题目描述输入格式输出格式样例 #1样例输入 #1样例输出 #1提示思路TLE算法具体思想TLE特例AC思想代码实现备注题目 链接 https://www.luogu.com.cn/problem/CF1561C 字面描述 Deep Down Below 题面翻译…...
秒杀项目之服务调用分布式session
目录 nginx动静分离 服务调用 创建配置zmall-cart购物车模块 创建配置zmall-order订单模块 服务调用 spring session实战 什么是Spring Session 为什么要使用Spring Session 错误案例展示 配置spring-session 二级域名问题 用户登录 nginx动静分离 第1步ÿ…...
聊聊什么是架构,你理解对了吗?
什么是架构?软件有架构?建筑也有架构?它们有什么相同点和不同点? 下面咱们就介绍一下,容易混淆的几个概念 一、系统与子系统 系统 泛指由一群有关联的个体组成,根据某种规则运作,能完成个别元件不能单独完成的工作的群体。它的意思是 “总体”、“整体”或“联盟” 子系…...
java多线程开发
1.并发和并行 并发:同一时间段内多个任务同时进行。 并行:同一时间点多个任务同时进行。 2.进程线程 进程(Process):进程是程序的一次动态执行过程,它经历了从代码加载、执行、到执行完毕的一个完整过程…...
杂记7--opencv的ar码模块学习
背景:项目需要用到marker知识,所以到官网上临时补一些知识。 概要:主要介绍marker一些接口的含义,纯属个人理解,有误则希望大佬不吝赐教 1、 涉及ar码操作学习,其头文件为: #include <op…...
[项目设计]高并发内存池
目录 1、项目介绍 2、高并发内存池整体框架设计 3、thread cache <1>thread cache 哈希桶对齐规则 <2>Thread Cache类设计 4、Central Cache <1>Central Cache类设计 5、page cache <1>Page Cache类设计 6、性能分析 <1>定长内存池实现…...
28岁才转行软件测试,目前32了,我的一些经历跟感受
我是92年的,算是最早的90后,现在跟你介绍的时候还恬不知耻的说我是90后,哈哈,计算机专业普通本科毕业。在一个二线城市,毕业后因为自身能力问题、认知水平问题,再加上运气不好,换过多份工作&…...
Python导入模块的3种方式
很多初学者经常遇到这样的问题,即自定义 Python 模板后,在其它文件中用 import(或 from...import) 语句引入该文件时,Python 解释器同时如下错误:ModuleNotFoundError: No module named 模块名意思是 Pytho…...
select 与 where、order by、limit 子句执行优先级比较
当 select 和 其他三种语句的一者或者多者同时出现时,他们之间是存在执行先后顺序的。 他们的优先级顺序是:where > select > order by > limit 目录 1、select 与 where 2、select 与 order by 3、order by 与 limit 4、优先级证明 1、s…...
Linux内核并发与竞争-原子操作
一.原子操作的概念首先看一下原子操作,原子操作就是指不能再进一步分割的操作,一般原子操作用于变量或者位操作。假如现在要对无符号整形变量 a 赋值,值为 3,对于 C 语言来讲很简单,直接就是: a3但是 C 语言…...
Java笔记-泛型的使用
参考: Java 泛型,你了解类型擦除吗? 泛型的使用 1、泛型的定义 可以广泛使用的类型,一种较为准确的说法就是为了参数化类型,或者说可以将类型当作参数传递给一个类或者是方法。 2、泛型的使用 2.1泛型类 public c…...
特斯拉无人驾驶解读
来源于Tesla AI Day Tesla无人驾驶算法的核心任务就是如何理解我们所看到的一切呢?也就是说,不使用高端的设备,比如激光雷达,仅仅使用摄像头就能够将任务做得很好。Tesla使用环绕型的8个摄像头获得输入。 第一步是特征提取模块Backbone,无论什么任务都离不开特征…...
生物素-琥珀酰亚胺酯Biotin-NHS;CAS号:35013-72-0;可对溶液中的抗体,蛋白质和任何其他含伯胺的大分子进行简单有效的生物素标记。
结构式: 生物素-琥珀酰亚胺酯Biotin NHS CAS号:35013-72-0 英文名称:Biotin-NHS 中文名称:D-生物素 N-羟基琥珀酰亚胺酯;生物素-琥珀酰亚胺酯 CAS号:35013-72-0 密度:1.50.1 …...
Maven_第五章 核心概念
目录第五章 其他核心概念1、生命周期①作用②三个生命周期③特点2、插件和目标①插件②目标3、仓库第五章 其他核心概念 1、生命周期 ①作用 为了让构建过程自动化完成,Maven 设定了三个生命周期,生命周期中的每一个环节对应构建过程中的一个操作。 …...
【深度学习】人脸识别工程化落地
文章目录前言1、facenet2、使用2.1.其它blog2.2 实践总结前言 老早以前就希望能写一篇关于人脸识别的工程化落地的案例,一年前做疲劳驾驶时使用的dlib插件,它封装好了,人脸检测、对齐、相似度计算三个部分,就是插件比较难装,但同时也少了很多…...
AOP面向切面编程思想。
目录 一、AOP工作流程 1、基本概念 2、AOP工作流程 二、AOP核心配置 1、AOP切入点表达式 2、AOP通知类型 三、AOP通知获取数据 1、获取参数 2、获取返回值 3、获取异常 四、AOP事务管理 1、Spring事务简介 2、Spring事务角色 3、事务属性 一、AOP工作流程 1、…...
实验7-变治技术及动态规划初步
目录 1.统计个数 2.数塔dp -A 3.Horspool算法 4.计数排序 5.找零问题1-最少硬币 1.统计个数 【问题描述】有n个数、每个元素取值在1到9之间,试统计每个数的个数 【输入形式】第一行,n的值;第二行...
JVM垃圾回收机制GC理解
目录JVM垃圾回收分代收集如何识别垃圾引用计数法可达性分析法引用关系四种类型: 强、软、弱、虚强引用软引用 SoftReference弱引用 WeakReferenceWeakHashMap软引用与虚引用的使用场景虚引用与引用队列引用队列虚引用 PhantomReference垃圾回收算法引用计数复制 Cop…...
C++中的容器
1.1 线性容器1)std::array看到这个容器的时候肯定会出现这样的问题:为什么要引入 std::array 而不是直接使用 std::vector?已经有了传统数组,为什么要用 std::array?先回答第一个问题,与 std::vector 不同,…...
2023备战金三银四,Python自动化软件测试面试宝典合集(五)
接上篇八、抓包与网络协议8.1 抓包工具怎么用 我原来的公司对于抓包这块,在 App 的测试用得比较多。我们会使用 fiddler 抓取数据检查结果,定位问题,测试安全,制造弱网环境;如:抓取数据通过查看请求数据,请…...
Admin.Net中的消息通信SignalR解释
定义集线器接口 IOnlineUserHub public interface IOnlineUserHub {/// 在线用户列表Task OnlineUserList(OnlineUserList context);/// 强制下线Task ForceOffline(object context);/// 发布站内消息Task PublicNotice(SysNotice context);/// 接收消息Task ReceiveMessage(…...
Robots.txt 文件
什么是robots.txt? robots.txt 是一个位于网站根目录下的文本文件(如:https://example.com/robots.txt),它用于指导网络爬虫(如搜索引擎的蜘蛛程序)如何抓取该网站的内容。这个文件遵循 Robots…...
C++八股 —— 单例模式
文章目录 1. 基本概念2. 设计要点3. 实现方式4. 详解懒汉模式 1. 基本概念 线程安全(Thread Safety) 线程安全是指在多线程环境下,某个函数、类或代码片段能够被多个线程同时调用时,仍能保证数据的一致性和逻辑的正确性…...
是否存在路径(FIFOBB算法)
题目描述 一个具有 n 个顶点e条边的无向图,该图顶点的编号依次为0到n-1且不存在顶点与自身相连的边。请使用FIFOBB算法编写程序,确定是否存在从顶点 source到顶点 destination的路径。 输入 第一行两个整数,分别表示n 和 e 的值(1…...
python执行测试用例,allure报乱码且未成功生成报告
allure执行测试用例时显示乱码:‘allure’ �����ڲ����ⲿ���Ҳ���ǿ�&am…...
HashMap中的put方法执行流程(流程图)
1 put操作整体流程 HashMap 的 put 操作是其最核心的功能之一。在 JDK 1.8 及以后版本中,其主要逻辑封装在 putVal 这个内部方法中。整个过程大致如下: 初始判断与哈希计算: 首先,putVal 方法会检查当前的 table(也就…...
【p2p、分布式,区块链笔记 MESH】Bluetooth蓝牙通信 BLE Mesh协议的拓扑结构 定向转发机制
目录 节点的功能承载层(GATT/Adv)局限性: 拓扑关系定向转发机制定向转发意义 CG 节点的功能 节点的功能由节点支持的特性和功能决定。所有节点都能够发送和接收网格消息。节点还可以选择支持一个或多个附加功能,如 Configuration …...
uniapp 小程序 学习(一)
利用Hbuilder 创建项目 运行到内置浏览器看效果 下载微信小程序 安装到Hbuilder 下载地址 :开发者工具默认安装 设置服务端口号 在Hbuilder中设置微信小程序 配置 找到运行设置,将微信开发者工具放入到Hbuilder中, 打开后出现 如下 bug 解…...
[论文阅读]TrustRAG: Enhancing Robustness and Trustworthiness in RAG
TrustRAG: Enhancing Robustness and Trustworthiness in RAG [2501.00879] TrustRAG: Enhancing Robustness and Trustworthiness in Retrieval-Augmented Generation 代码:HuichiZhou/TrustRAG: Code for "TrustRAG: Enhancing Robustness and Trustworthin…...
comfyui 工作流中 图生视频 如何增加视频的长度到5秒
comfyUI 工作流怎么可以生成更长的视频。除了硬件显存要求之外还有别的方法吗? 在ComfyUI中实现图生视频并延长到5秒,需要结合多个扩展和技巧。以下是完整解决方案: 核心工作流配置(24fps下5秒120帧) #mermaid-svg-yP…...
