Codeforces practice C++ 2024/9/11 - 2024/9/13
D. Mathematical Problem
Codeforces Round 954 (Div. 3)
原题链接:https://codeforces.com/contest/1986/problem/D
题目标签分类:brute force,dp,greedy,implementation,math,two pointers
题目难度:1400
题目大意:
给你一个长度为 n 的字符串,只由 0 到 9 这些字符组成,你需要往这个字符串中插入 n - 2 个 运算符,规定插入的运算符只有 * 和 + 两种。
输入:
输出:
题目做法:
AC代码 :
#include<bits/stdc++.h>
//#define int long long
//#define int __int128
#define loop(i, n) for(int i = 0; i < n; i++)
#define repeat(i, start, end, step) for(int i = start; i < end; i += step)
#define FastIO ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);using namespace std;
using ll = long long;
using bigint = __int128;const int maxn = 2e5 + 10;
const int modi = 1e9 + 7;int n, inips = 0, news[20];
string s, str[20];
int tonum(string t) {int res = 0;for(int i = 0; i < t.length(); i++) {res *= 10;res += t[i] - '0';}return res;
}
int construct(int x = -1, int y = -1) {inips = 0;for(int i = 0; i < n; i++) str[i] = s[i];for(int i = 0; i < n; i++) {if(i == x || i == y) {str[i + 1] = str[i] + s[i + 1];str[i] = "-";}}for(int i = 0; i < n; i++) if(str[i] != "-") news[inips++] = tonum(str[i]);int dp[20][2];dp[0][0] = dp[0][1] = news[0];for(int i = 1; i < inips; i++) {dp[i][0] = min(dp[i - 1][1] + news[i], dp[i - 1][0] + news[i]);dp[i][1] = min({dp[i][0], dp[i - 1][1] * news[i], dp[i - 1][0] * news[i]});}return dp[inips - 1][1];
}
void solve() {cin >> n >> s;int res = 1e9 + 10;if(n == 2) {cout << construct(0) << '\n';return ;}for(int i = 0; i < n - 1; i++) res = min(res, construct(i));cout << res << '\n';
}signed main() {FastIOint TestCase = 1;cin >> TestCase;while(TestCase--) solve();
}
事后ps:Dp比较好像也很好写,就两种状态,预处理也不是很难。
D. Maximize the Root
Educational Codeforces Round 168 (Rated for Div. 2)
原题链接:https://codeforces.com/problemset/problem/1997/D
题目标签分类:binary search,dfs and similar,dp,greedy,trees
题目难度:1500
题目大意:
给一颗树,规定编号为1的节点为根节点,每个节点上初始会有一个值,你每次可以进行操作,这个操作是选定一个非叶子节点的节点,给此节点上的值加一,此节点除了该节点外的子树种的节点上的值均减去1。规定每次操作后树上所有节点的值非负。
输入:
共 t 组输入数据。
每组数据有三行,第一行输入一个变量 n,代表这棵树有 n 个节点,第二行有 n 个变量 ai 分别代表初始的时候每个节点上的值,第三行有 n - 1 个变量代表树上每个节点的父节点,n - 1 是因为从下标从2开始,1号节点默认为根节点。
输出:
进行不限次数的合法调整过后根节点上的最大值。
题目做法:
如果根节点上的值确定了,那么这棵树的所有节点上的最小数值也就决定了。
因为结果显然是呈线性变化的,所以可以对答案进行二分,满足则往更大里搜索答案,反之往更小搜索, 函数的写法应该是
一整颗树来检测当前二分的答案是否满足。dfs的时间复杂度是
,二分的复杂度是
,所以总复杂度是
。
AC代码 :
#include<bits/stdc++.h>
#define int long long
//#define int __int128
#define pb push_back
#define loop(i, n) for(int i = 0; i < n; i++)
#define rep(i, start, end, step) for(int i = start; i <= end; i += step)
#define FastIO ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);using namespace std;
using ll = long long;
using bigint = __int128;const int maxn = 2e5 + 10;
const int modi = 1e9 + 7;int a[maxn] ,tval;
vector<int> tr[maxn];
bool check(int now, int val) {bool judge = 1;if(val < 0 || val >= 1e18 + 10) return 0;if(tr[now].size() == 0) return (max((ll)0, val - a[now]) <= 0);for(auto it:tr[now]) {judge &= check(it,val * (now != 1) + max((ll)0, val - a[now]));}return judge;
}void solve() {int n, l = 0, r = 1e18 + 10, ans = 0 ,t;cin >> n;loop(i, n) cin >> a[i + 1], tr[i + 1].clear();rep(i, 2, n, 1) cin >> t, tr[t].pb(i);while(l <= r) {int mid = (l + r) / 2;if(check(1, mid)) {ans = max(ans, mid);l = mid + 1;}else r = mid - 1;}cout << ans << '\n';
}signed main() {FastIO int TestCase = 1;cin >> TestCase;while(TestCase--) solve();
}
事后ps:分析整体情况后还是比较容易想到二分答案的,dfs的时候有细节需要注意可能会爆long long,我二分写得挺烂的,还是按板子来比较稳妥。
A. Distanced Coloring
EPIC Institute of Technology Round August 2024 (Div. 1 + Div. 2)
原题链接:https://codeforces.com/problemset/problem/2002/A
题目标签分类:constructive algorithms,implementation,math
题目难度:800
题目大意:
给出 n * m 的网格和一个 k ,满足如下条件的两个点为同一颜色,求填满网格的最小颜色数目。
条件:
题目做法:
在一行上最多就用k个颜色就能填满,如果k小于n的话,k大于n的话就用n个。在同一列上同理。这样最小,还是比较好像的,因为等于k的时候间距最小。
AC代码 :
#include<bits/stdc++.h>
//#define int long long
//#define int __int128
#define pb push_back
#define loop(i, n) for(int i = 0; i < n; i++)
#define rep(i, start, end, step) for(int i = start; i <= end; i += step)
#define FastIO ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);using namespace std;
using ll = long long;
using bigint = __int128;const int maxn = 2e5 + 10;
const int modi = 1e9 + 7;void solve() {int n, m, k;cin >> n >> m >> k;cout << min(n, k) * min(m, k) << '\n';
}signed main() {FastIO int TestCase = 1;cin >> TestCase;while(TestCase--) solve();
}
B. Removals Game
EPIC Institute of Technology Round August 2024 (Div. 1 + Div. 2)
原题链接:https://codeforces.com/problemset/problem/2002/B
题目标签分类:constructive algorithms,games
题目难度:1000
题目大意:
Alice 和 Bob 一开始会分别拿到两个全排列数组,
输入:
输出:
题目做法:
AC代码 :
#include<bits/stdc++.h>
#define int long long
//#define int __int128
#define pb push_back
#define loop(i, n) for(int i = 0; i < n; i++)
#define rep(i, start, end, step) for(int i = start; i <= end; i += step)
#define FastIO ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);using namespace std;
using ll = long long;
using bigint = __int128;const int maxn = 2e5 + 10;
const int modi = 1e9 + 7;void solve() {int n;cin >> n;int a[n],b[n];for(int i = 0; i < n; i++) cin >> a[i];for(int i = 0; i < n; i++) cin >> b[i];bool is = 1, is2 = 1;rep(i, 0, n - 1, 1) is &= (a[i] == b[i]), is2 &= (a[n - 1 - i] == b[i]);if(is || is2) {cout << "Bob" << '\n';return ;}cout << "Alice" << '\n';
}signed main() {FastIO int TestCase = 1;cin >> TestCase;while(TestCase--) solve();
}
事后ps:
A. Legs
Codeforces Round 962 (Div. 3)
原题链接:https://codeforces.com/contest/1996/problem/A
题目标签分类:binary search,math,ternary search
题目难度:800
题目大意:
输入:
输出:
题目做法:
AC代码 :
#include<bits/stdc++.h>
#define int long long
//#define int __int128
#define pb push_back
#define loop(i, n) for(int i = 0; i < n; i++)
#define rep(i, start, end, step) for(int i = start; i <= end; i += step)
#define FastIO ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);using namespace std;
using ll = long long;
using bigint = __int128;const int maxn = 2e5 + 10;
const int modi = 1e9 + 7;void solve() {int n;cin >> n;cout << n / 4 + (n % 4 != 0) << '\n';
}signed main() {FastIO int TestCase = 1;cin >> TestCase;while(TestCase--) solve();
}
D. Paint the Tree
Codeforces Round 947 (Div. 1 + Div. 2)
原题链接:https://codeforces.com/problemset/problem/1975/D
题目标签分类:constructive algorithms,games
题目难度:1700
题目大意:
输入:
输出:
题目做法:
AC代码 :
#include<bits/stdc++.h>
#define int long long
//#define int __int128
#define pb push_back
#define loop(i, n) for(int i = 0; i < n; i++)
#define rep(i, start, end, step) for(int i = start; i <= end; i += step)
#define FastIO ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);using namespace std;
using ll = long long;
using bigint = __int128;const int maxn = 2e5 + 10;
const int modi = 1e9 + 7;void solve() {int n;cin >> n;int a[n],b[n];for(int i = 0; i < n; i++) cin >> a[i];for(int i = 0; i < n; i++) cin >> b[i];bool is = 1, is2 = 1;rep(i, 0, n - 1, 1) is &= (a[i] == b[i]), is2 &= (a[n - 1 - i] == b[i]);if(is || is2) {cout << "Bob" << '\n';return ;}cout << "Alice" << '\n';
}signed main() {FastIO int TestCase = 1;cin >> TestCase;while(TestCase--) solve();
}
事后ps:
相关文章:

Codeforces practice C++ 2024/9/11 - 2024/9/13
D. Mathematical Problem Codeforces Round 954 (Div. 3) 原题链接:https://codeforces.com/contest/1986/problem/D 题目标签分类:brute force,dp,greedy,implementation,math,two pointers…...
RabbitMQ创建交换机和队列——配置类 注解
交换机的类型 Fanout:广播,将消息交给所有绑定到交换机的队列。 Direct:订阅,基于RoutingKey(路由key)发送给订阅了消息的队列。 Topic:通配符订阅,与Direct类似,只不…...

proteus+51单片机+AD/DA学习5
目录 1.DA转换原理 1.1基本概念 1.1.1DA的简介 1.1.2DA0832芯片 1.1.3PCF8591芯片 1.2代码 1.2.1DAC8053的代码 1.2.2PCF8951的代码 1.3仿真 1.3.1DAC0832的仿真 1.3.2PFC8951的仿真 2.AD转换原理 2.1AD的基本概念 2.1.1AD的简介 2.1.2ADC0809的介绍 2.1.3XPT2…...

【Python机器学习】长短期记忆网络(LSTM)
目录 随时间反向传播 实践 模型的使用 脏数据 “未知”词条的处理 字符级建模(英文) 生成聊天文章 进一步生成文本 文本生成的问题:内容不受控 其他记忆机制 更深的网络 尽管在序列数据中,循环神经网络为对各种语言关系…...

【Go】使用Goland创建第一个Go项目
✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,…...

STM32学习笔记(一、使用DAP仿真器下载程序)
我们想要使用32单片机,总共包含四个步骤: 1、硬件连接 2、仿真器配置 3、编写程序 4、下载程序 一、第一个问题(硬件连接):如何进行硬件连接,才能够启动32板子并能够下载程序呢? 答&#…...

储能运维管理云平台解决方案EMS能量管理系统
在储能行业蓬勃发展的今天,储能运维管理的重要性日益凸显。而储能运维管理云平台的出现,正为储能系统的稳定运行和高效管理注入了新的活力。 一、储能运维管理面临的挑战 传统的储能运维管理方式往往依赖人工巡检和现场操作,存在诸多问题。比…...
网络药理学:16、速通流程版
一、筛选疾病靶点 GeneCards 下载数据得到GeneCards-SearchResult.csv通过Relevance score≥1.0得到GeneCards.csv步骤2只保留Gene Symbol,即基因名这一列得到GeneCards_gene_names.csv OMIM 下载数据得到OMIM-Gene-Map-Retrieval.xlsx只保留Gene/Locus…...
P2515 [HAOI2010] 软件安装
~~~~~ P2515 [HAOI2010] 软件安装 ~~~~~ 总题单链接 思路 ~~~~~ 发现构成的图是一个森林和一些环。 ~~~~~ 对于森林,建一个虚点然后树形 D P DP DP 即可。 ~~~~~ 对于环,发现要么把这个环上的每一个点都选了,要么每一个都不选。所以可以先缩…...

51单片机快速入门之定时器和计数器
51单片机快速入门之定时器 断开外部输入 晶振振荡 假设为 12MHz 12分频之后,为1MHz 当其从0-65536 时,需要65536μs 微秒 也就是65.536ms 毫秒 溢出(值>65536 时)>中断>执行中断操作 假设需要1ms后产生溢出,则需要设置初始值为64536 此时定时器会从 64536 开始计…...

【计算机网络 - 基础问题】每日 3 题(一)
✍个人博客:Pandaconda-CSDN博客 📣专栏地址:http://t.csdnimg.cn/fYaBd 📚专栏简介:在这个专栏中,我将会分享 C 面试中常见的面试题给大家~ ❤️如果有收获的话,欢迎点赞👍收藏&…...

Unity全面取消Runtime费用 安装游戏不再收版费
Unity宣布他们已经废除了争议性的Runtime费用,该费用于2023年9月引入,定于1月1日开始收取。Runtime费用起初是打算根据使用Unity引擎安装游戏的次数收取版权费。2023年9月晚些时候,该公司部分收回了计划,称Runtime费用只适用于订阅…...

IDEA测试类启动报 “java: 常量字符串过长” 解决办法
目录标题 问题描述问题分析解决办法其他办法 问题描述 问题分析 字符串长度过长,导致 idea 默认使用的 javac 编译器编译不了。 查询资料发现,原因是javac在编译期间,常量字符串最大长度为65534。 解决办法 Javac 编译器改为 Eclipse 编译…...
计算机科学基础 -- 访存单元
访存单元(Memory Access Unit)的概念 访存单元(Memory Access Unit) 是处理器中的一个关键模块,负责处理指令中的内存访问操作,包括从内存中读取数据和将数据写入内存。由于内存访问速度通常比处理器执行速…...
Linux压缩、解压缩、查看压缩内容详解使用(tar、gzip、bzip2、xz、jar、war、aar)
在Linux环境中,你可以使用各种命令来压缩、解压缩和查看不同类型的压缩包。以下是常用的命令和操作说明,包括tar、gzip、bzip2、xz、jar、war、aar等类型的包文件。 1. tar命令:压缩、解压、查看tar包 压缩: tar -cvf archive.…...
StreamReader 和 StreamWriter提供自动处理字符编码的功能
FileStream、StreamReader 和 StreamWriter 都用于文件操作,但它们的设计目标和使用方式有所不同。下面是它们之间的主要差异以及如何结合使用的说明: 1. FileStream 用途:提供对文件的字节流访问,用于读写二进制数据。特点&…...

Gitlab备份、迁移、恢复和升级(Gitlab Backup, migration, recovery, and upgrade)
💝💝💝欢迎来到我的博客,很高兴能够在这里和您见面!希望您在这里可以感受到一份轻松愉快的氛围,不仅可以获得有趣的内容和知识,也可以畅所欲言、分享您的想法和见解。 推荐:Linux运维老纪的首页…...
MySQL:INSERT command denied to user
异常: INSERT command denied to user 解决办法: 请检查一下 MySQL 帐号是否有相应的权限...

【Android安全】Ubuntu 16.04安装GDB和GEF
1. 安装GDB sudo apt install gdb-multiarch 2. 安装GEF(GDB Enhanced Features) 官网地址:https://github.com/hugsy/gef 2.1 安装2021.10版本 但是在Ubuntu 16.04上,bash -c "$(curl -fsSL https://gef.blah.cat/sh)"等命令不好使&…...
ISO 21434与网络安全管理系统(CSMS)的协同作用
ISO/SAE 21434与CSMS(网络安全管理系统)之间的关系主要体现在以下几个方面: 提供指导框架:ISO/SAE 21434《道路车辆—网络安全工程》是一项国际标准,它为汽车行业提供了实施网络安全管理系统的国际认可的方法和最佳实…...
零门槛NAS搭建:WinNAS如何让普通电脑秒变私有云?
一、核心优势:专为Windows用户设计的极简NAS WinNAS由深圳耘想存储科技开发,是一款收费低廉但功能全面的Windows NAS工具,主打“无学习成本部署” 。与其他NAS软件相比,其优势在于: 无需硬件改造:将任意W…...
利用ngx_stream_return_module构建简易 TCP/UDP 响应网关
一、模块概述 ngx_stream_return_module 提供了一个极简的指令: return <value>;在收到客户端连接后,立即将 <value> 写回并关闭连接。<value> 支持内嵌文本和内置变量(如 $time_iso8601、$remote_addr 等)&a…...
React hook之useRef
React useRef 详解 useRef 是 React 提供的一个 Hook,用于在函数组件中创建可变的引用对象。它在 React 开发中有多种重要用途,下面我将全面详细地介绍它的特性和用法。 基本概念 1. 创建 ref const refContainer useRef(initialValue);initialValu…...

基于Flask实现的医疗保险欺诈识别监测模型
基于Flask实现的医疗保险欺诈识别监测模型 项目截图 项目简介 社会医疗保险是国家通过立法形式强制实施,由雇主和个人按一定比例缴纳保险费,建立社会医疗保险基金,支付雇员医疗费用的一种医疗保险制度, 它是促进社会文明和进步的…...
VTK如何让部分单位不可见
最近遇到一个需求,需要让一个vtkDataSet中的部分单元不可见,查阅了一些资料大概有以下几种方式 1.通过颜色映射表来进行,是最正规的做法 vtkNew<vtkLookupTable> lut; //值为0不显示,主要是最后一个参数,透明度…...

dify打造数据可视化图表
一、概述 在日常工作和学习中,我们经常需要和数据打交道。无论是分析报告、项目展示,还是简单的数据洞察,一个清晰直观的图表,往往能胜过千言万语。 一款能让数据可视化变得超级简单的 MCP Server,由蚂蚁集团 AntV 团队…...

使用 Streamlit 构建支持主流大模型与 Ollama 的轻量级统一平台
🎯 使用 Streamlit 构建支持主流大模型与 Ollama 的轻量级统一平台 📌 项目背景 随着大语言模型(LLM)的广泛应用,开发者常面临多个挑战: 各大模型(OpenAI、Claude、Gemini、Ollama)接口风格不统一;缺乏一个统一平台进行模型调用与测试;本地模型 Ollama 的集成与前…...
JAVA后端开发——多租户
数据隔离是多租户系统中的核心概念,确保一个租户(在这个系统中可能是一个公司或一个独立的客户)的数据对其他租户是不可见的。在 RuoYi 框架(您当前项目所使用的基础框架)中,这通常是通过在数据表中增加一个…...

在 Spring Boot 中使用 JSP
jsp? 好多年没用了。重新整一下 还费了点时间,记录一下。 项目结构: pom: <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://ww…...

从物理机到云原生:全面解析计算虚拟化技术的演进与应用
前言:我的虚拟化技术探索之旅 我最早接触"虚拟机"的概念是从Java开始的——JVM(Java Virtual Machine)让"一次编写,到处运行"成为可能。这个软件层面的虚拟化让我着迷,但直到后来接触VMware和Doc…...