当前位置: 首页 > news >正文

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^9T105,n105,ki105,ki105,ai,j109

题目描述

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阶段处理

  1. 算出每组打怪加能力的情况下每一个怪兽所对应初始能力值,并取max
  2. nnn个max从小到大排序,依次循环,看每个max加上对应任务里的元素数(能加多少次能力),是否能满足下一个max,是 -> continue ,否 -> 加到下一个max。

时间复杂度:O(Σk⋅log(Σk))≈2e6O(Σk·log(Σk))≈2e6O(Σklog(Σ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步&#xff…...

聊聊什么是架构,你理解对了吗?

什么是架构?软件有架构?建筑也有架构?它们有什么相同点和不同点? 下面咱们就介绍一下,容易混淆的几个概念 一、系统与子系统 系统 泛指由一群有关联的个体组成,根据某种规则运作,能完成个别元件不能单独完成的工作的群体。它的意思是 “总体”、“整体”或“联盟” 子系…...

java多线程开发

1.并发和并行 并发&#xff1a;同一时间段内多个任务同时进行。 并行&#xff1a;同一时间点多个任务同时进行。 2.进程线程 进程&#xff08;Process&#xff09;&#xff1a;进程是程序的一次动态执行过程&#xff0c;它经历了从代码加载、执行、到执行完毕的一个完整过程…...

杂记7--opencv的ar码模块学习

背景&#xff1a;项目需要用到marker知识&#xff0c;所以到官网上临时补一些知识。 概要&#xff1a;主要介绍marker一些接口的含义&#xff0c;纯属个人理解&#xff0c;有误则希望大佬不吝赐教 1、 涉及ar码操作学习&#xff0c;其头文件为&#xff1a; #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年的&#xff0c;算是最早的90后&#xff0c;现在跟你介绍的时候还恬不知耻的说我是90后&#xff0c;哈哈&#xff0c;计算机专业普通本科毕业。在一个二线城市&#xff0c;毕业后因为自身能力问题、认知水平问题&#xff0c;再加上运气不好&#xff0c;换过多份工作&…...

Python导入模块的3种方式

很多初学者经常遇到这样的问题&#xff0c;即自定义 Python 模板后&#xff0c;在其它文件中用 import&#xff08;或 from...import&#xff09; 语句引入该文件时&#xff0c;Python 解释器同时如下错误&#xff1a;ModuleNotFoundError: No module named 模块名意思是 Pytho…...

select 与 where、order by、limit 子句执行优先级比较

当 select 和 其他三种语句的一者或者多者同时出现时&#xff0c;他们之间是存在执行先后顺序的。 他们的优先级顺序是&#xff1a;where > select > order by > limit 目录 1、select 与 where 2、select 与 order by 3、order by 与 limit 4、优先级证明 1、s…...

Linux内核并发与竞争-原子操作

一.原子操作的概念首先看一下原子操作&#xff0c;原子操作就是指不能再进一步分割的操作&#xff0c;一般原子操作用于变量或者位操作。假如现在要对无符号整形变量 a 赋值&#xff0c;值为 3&#xff0c;对于 C 语言来讲很简单&#xff0c;直接就是&#xff1a; a3但是 C 语言…...

Java笔记-泛型的使用

参考&#xff1a; Java 泛型&#xff0c;你了解类型擦除吗&#xff1f; 泛型的使用 1、泛型的定义 可以广泛使用的类型&#xff0c;一种较为准确的说法就是为了参数化类型&#xff0c;或者说可以将类型当作参数传递给一个类或者是方法。 2、泛型的使用 2.1泛型类 public c…...

特斯拉无人驾驶解读

来源于Tesla AI Day Tesla无人驾驶算法的核心任务就是如何理解我们所看到的一切呢?也就是说,不使用高端的设备,比如激光雷达,仅仅使用摄像头就能够将任务做得很好。Tesla使用环绕型的8个摄像头获得输入。 第一步是特征提取模块Backbone,无论什么任务都离不开特征…...

生物素-琥珀酰亚胺酯Biotin-NHS;CAS号:35013-72-0;可对溶液中的抗体,蛋白质和任何其他含伯胺的大分子进行简单有效的生物素标记。

结构式&#xff1a; ​ 生物素-琥珀酰亚胺酯Biotin NHS CAS号&#xff1a;35013-72-0 英文名称&#xff1a;Biotin-NHS 中文名称&#xff1a;D-生物素 N-羟基琥珀酰亚胺酯&#xff1b;生物素&#xff0d;琥珀酰亚胺酯 CAS号&#xff1a;35013-72-0 密度&#xff1a;1.50.1 …...

Maven_第五章 核心概念

目录第五章 其他核心概念1、生命周期①作用②三个生命周期③特点2、插件和目标①插件②目标3、仓库第五章 其他核心概念 1、生命周期 ①作用 为了让构建过程自动化完成&#xff0c;Maven 设定了三个生命周期&#xff0c;生命周期中的每一个环节对应构建过程中的一个操作。 …...

【深度学习】人脸识别工程化落地

文章目录前言1、facenet2、使用2.1.其它blog2.2 实践总结前言 老早以前就希望能写一篇关于人脸识别的工程化落地的案例&#xff0c;一年前做疲劳驾驶时使用的dlib插件&#xff0c;它封装好了&#xff0c;人脸检测、对齐、相似度计算三个部分,就是插件比较难装,但同时也少了很多…...

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垃圾回收分代收集如何识别垃圾引用计数法可达性分析法引用关系四种类型&#xff1a; 强、软、弱、虚强引用软引用 SoftReference弱引用 WeakReferenceWeakHashMap软引用与虚引用的使用场景虚引用与引用队列引用队列虚引用 PhantomReference垃圾回收算法引用计数复制 Cop…...

C++中的容器

1.1 线性容器1&#xff09;std::array看到这个容器的时候肯定会出现这样的问题&#xff1a;为什么要引入 std::array 而不是直接使用 std::vector&#xff1f;已经有了传统数组&#xff0c;为什么要用 std::array?先回答第一个问题&#xff0c;与 std::vector 不同&#xff0c…...

2023备战金三银四,Python自动化软件测试面试宝典合集(五)

接上篇八、抓包与网络协议8.1 抓包工具怎么用 我原来的公司对于抓包这块&#xff0c;在 App 的测试用得比较多。我们会使用 fiddler 抓取数据检查结果&#xff0c;定位问题&#xff0c;测试安全&#xff0c;制造弱网环境;如&#xff1a;抓取数据通过查看请求数据&#xff0c;请…...

解决Ubuntu22.04 VMware失败的问题 ubuntu入门之二十八

现象1 打开VMware失败 Ubuntu升级之后打开VMware上报需要安装vmmon和vmnet&#xff0c;点击确认后如下提示 最终上报fail 解决方法 内核升级导致&#xff0c;需要在新内核下重新下载编译安装 查看版本 $ vmware -v VMware Workstation 17.5.1 build-23298084$ lsb_release…...

ESP32读取DHT11温湿度数据

芯片&#xff1a;ESP32 环境&#xff1a;Arduino 一、安装DHT11传感器库 红框的库&#xff0c;别安装错了 二、代码 注意&#xff0c;DATA口要连接在D15上 #include "DHT.h" // 包含DHT库#define DHTPIN 15 // 定义DHT11数据引脚连接到ESP32的GPIO15 #define D…...

相机从app启动流程

一、流程框架图 二、具体流程分析 1、得到cameralist和对应的静态信息 目录如下: 重点代码分析: 启动相机前,先要通过getCameraIdList获取camera的个数以及id,然后可以通过getCameraCharacteristics获取对应id camera的capabilities(静态信息)进行一些openCamera前的…...

unix/linux,sudo,其发展历程详细时间线、由来、历史背景

sudo 的诞生和演化,本身就是一部 Unix/Linux 系统管理哲学变迁的微缩史。来,让我们拨开时间的迷雾,一同探寻 sudo 那波澜壮阔(也颇为实用主义)的发展历程。 历史背景:su的时代与困境 ( 20 世纪 70 年代 - 80 年代初) 在 sudo 出现之前,Unix 系统管理员和需要特权操作的…...

IoT/HCIP实验-3/LiteOS操作系统内核实验(任务、内存、信号量、CMSIS..)

文章目录 概述HelloWorld 工程C/C配置编译器主配置Makefile脚本烧录器主配置运行结果程序调用栈 任务管理实验实验结果osal 系统适配层osal_task_create 其他实验实验源码内存管理实验互斥锁实验信号量实验 CMISIS接口实验还是得JlINKCMSIS 简介LiteOS->CMSIS任务间消息交互…...

算法笔记2

1.字符串拼接最好用StringBuilder&#xff0c;不用String 2.创建List<>类型的数组并创建内存 List arr[] new ArrayList[26]; Arrays.setAll(arr, i -> new ArrayList<>()); 3.去掉首尾空格...

10-Oracle 23 ai Vector Search 概述和参数

一、Oracle AI Vector Search 概述 企业和个人都在尝试各种AI&#xff0c;使用客户端或是内部自己搭建集成大模型的终端&#xff0c;加速与大型语言模型&#xff08;LLM&#xff09;的结合&#xff0c;同时使用检索增强生成&#xff08;Retrieval Augmented Generation &#…...

CSS | transition 和 transform的用处和区别

省流总结&#xff1a; transform用于变换/变形&#xff0c;transition是动画控制器 transform 用来对元素进行变形&#xff0c;常见的操作如下&#xff0c;它是立即生效的样式变形属性。 旋转 rotate(角度deg)、平移 translateX(像素px)、缩放 scale(倍数)、倾斜 skewX(角度…...

省略号和可变参数模板

本文主要介绍如何展开可变参数的参数包 1.C语言的va_list展开可变参数 #include <iostream> #include <cstdarg>void printNumbers(int count, ...) {// 声明va_list类型的变量va_list args;// 使用va_start将可变参数写入变量argsva_start(args, count);for (in…...

Vite中定义@软链接

在webpack中可以直接通过符号表示src路径&#xff0c;但是vite中默认不可以。 如何实现&#xff1a; vite中提供了resolve.alias&#xff1a;通过别名在指向一个具体的路径 在vite.config.js中 import { join } from pathexport default defineConfig({plugins: [vue()],//…...