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

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号节点默认为根节点。

输出:

进行不限次数的合法调整过后根节点上的最大值。

题目做法:

如果根节点上的值确定了,那么这棵树的所有节点上的最小数值也就决定了。

因为结果显然是呈线性变化的,所以可以对答案进行二分,满足则往更大里搜索答案,反之往更小搜索,check 函数的写法应该是 dfs 一整颗树来检测当前二分的答案是否满足。dfs的时间复杂度是 n,二分的复杂度是 log\left ( n \right ),所以总复杂度是 O\left ( nlogn \right ) 。

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) 原题链接&#xff1a;https://codeforces.com/contest/1986/problem/D 题目标签分类&#xff1a;brute force&#xff0c;dp&#xff0c;greedy&#xff0c;implementation&#xff0c;math&#xff0c;two pointers…...

RabbitMQ创建交换机和队列——配置类 注解

交换机的类型 Fanout&#xff1a;广播&#xff0c;将消息交给所有绑定到交换机的队列。 Direct&#xff1a;订阅&#xff0c;基于RoutingKey&#xff08;路由key&#xff09;发送给订阅了消息的队列。 Topic&#xff1a;通配符订阅&#xff0c;与Direct类似&#xff0c;只不…...

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)

目录 随时间反向传播 实践 模型的使用 脏数据 “未知”词条的处理 字符级建模&#xff08;英文&#xff09; 生成聊天文章 进一步生成文本 文本生成的问题&#xff1a;内容不受控 其他记忆机制 更深的网络 尽管在序列数据中&#xff0c;循环神经网络为对各种语言关系…...

【Go】使用Goland创建第一个Go项目

✨✨ 欢迎大家来到景天科技苑✨✨ &#x1f388;&#x1f388; 养成好习惯&#xff0c;先赞后看哦~&#x1f388;&#x1f388; &#x1f3c6; 作者简介&#xff1a;景天科技苑 &#x1f3c6;《头衔》&#xff1a;大厂架构师&#xff0c;华为云开发者社区专家博主&#xff0c;…...

STM32学习笔记(一、使用DAP仿真器下载程序)

我们想要使用32单片机&#xff0c;总共包含四个步骤&#xff1a; 1、硬件连接 2、仿真器配置 3、编写程序 4、下载程序 一、第一个问题&#xff08;硬件连接&#xff09;&#xff1a;如何进行硬件连接&#xff0c;才能够启动32板子并能够下载程序呢&#xff1f; 答&#…...

储能运维管理云平台解决方案EMS能量管理系统

在储能行业蓬勃发展的今天&#xff0c;储能运维管理的重要性日益凸显。而储能运维管理云平台的出现&#xff0c;正为储能系统的稳定运行和高效管理注入了新的活力。 一、储能运维管理面临的挑战 传统的储能运维管理方式往往依赖人工巡检和现场操作&#xff0c;存在诸多问题。比…...

网络药理学:16、速通流程版

一、筛选疾病靶点 GeneCards 下载数据得到GeneCards-SearchResult.csv通过Relevance score≥1.0得到GeneCards.csv步骤2只保留Gene Symbol&#xff0c;即基因名这一列得到GeneCards_gene_names.csv OMIM 下载数据得到OMIM-Gene-Map-Retrieval.xlsx只保留Gene/Locus&#xf…...

P2515 [HAOI2010] 软件安装

~~~~~ P2515 [HAOI2010] 软件安装 ~~~~~ 总题单链接 思路 ~~~~~ 发现构成的图是一个森林和一些环。 ~~~~~ 对于森林&#xff0c;建一个虚点然后树形 D P DP DP 即可。 ~~~~~ 对于环&#xff0c;发现要么把这个环上的每一个点都选了&#xff0c;要么每一个都不选。所以可以先缩…...

51单片机快速入门之定时器和计数器

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

【计算机网络 - 基础问题】每日 3 题(一)

✍个人博客&#xff1a;Pandaconda-CSDN博客 &#x1f4e3;专栏地址&#xff1a;http://t.csdnimg.cn/fYaBd &#x1f4da;专栏简介&#xff1a;在这个专栏中&#xff0c;我将会分享 C 面试中常见的面试题给大家~ ❤️如果有收获的话&#xff0c;欢迎点赞&#x1f44d;收藏&…...

Unity全面取消Runtime费用 安装游戏不再收版费

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

IDEA测试类启动报 “java: 常量字符串过长” 解决办法

目录标题 问题描述问题分析解决办法其他办法 问题描述 问题分析 字符串长度过长&#xff0c;导致 idea 默认使用的 javac 编译器编译不了。 查询资料发现&#xff0c;原因是javac在编译期间&#xff0c;常量字符串最大长度为65534。 解决办法 Javac 编译器改为 Eclipse 编译…...

计算机科学基础 -- 访存单元

访存单元&#xff08;Memory Access Unit&#xff09;的概念 访存单元&#xff08;Memory Access Unit&#xff09; 是处理器中的一个关键模块&#xff0c;负责处理指令中的内存访问操作&#xff0c;包括从内存中读取数据和将数据写入内存。由于内存访问速度通常比处理器执行速…...

Linux压缩、解压缩、查看压缩内容详解使用(tar、gzip、bzip2、xz、jar、war、aar)

在Linux环境中&#xff0c;你可以使用各种命令来压缩、解压缩和查看不同类型的压缩包。以下是常用的命令和操作说明&#xff0c;包括tar、gzip、bzip2、xz、jar、war、aar等类型的包文件。 1. tar命令&#xff1a;压缩、解压、查看tar包 压缩&#xff1a; tar -cvf archive.…...

StreamReader 和 StreamWriter提供自动处理字符编码的功能

FileStream、StreamReader 和 StreamWriter 都用于文件操作&#xff0c;但它们的设计目标和使用方式有所不同。下面是它们之间的主要差异以及如何结合使用的说明&#xff1a; 1. FileStream 用途&#xff1a;提供对文件的字节流访问&#xff0c;用于读写二进制数据。特点&…...

Gitlab备份、迁移、恢复和升级(Gitlab Backup, migration, recovery, and upgrade)

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:Linux运维老纪的首页…...

MySQL:INSERT command denied to user

异常&#xff1a; INSERT command denied to user 解决办法&#xff1a; 请检查一下 MySQL 帐号是否有相应的权限...

【Android安全】Ubuntu 16.04安装GDB和GEF

1. 安装GDB sudo apt install gdb-multiarch 2. 安装GEF(GDB Enhanced Features) 官网地址&#xff1a;https://github.com/hugsy/gef 2.1 安装2021.10版本 但是在Ubuntu 16.04上&#xff0c;bash -c "$(curl -fsSL https://gef.blah.cat/sh)"等命令不好使&…...

ISO 21434与网络安全管理系统(CSMS)的协同作用

ISO/SAE 21434与CSMS&#xff08;网络安全管理系统&#xff09;之间的关系主要体现在以下几个方面&#xff1a; 提供指导框架&#xff1a;ISO/SAE 21434《道路车辆—网络安全工程》是一项国际标准&#xff0c;它为汽车行业提供了实施网络安全管理系统的国际认可的方法和最佳实…...

Vue 67 vuex 四个map方法的使用

mapState方法&#xff1a;用于帮助我们映射state中的数据为计算属性 computed: {//借助mapState生成计算属性&#xff1a;sum、school、subject&#xff08;对象写法&#xff09;...mapState({sum:sum,school:school,subject:subject}),//借助mapState生成计算属性&#xff1a;…...

Unity自带脚本之GameObject脚本

目录 GameObject基本成员变量 静态方法 创建自带几何体 1.查找对象 通过tag来查找对象 2查找多个对象 实例化对象&#xff08;克隆对象&#xff09;的方法 删除对象的方法 过场景不移除 Unity中的Object和C#中的万物之父的区别 成员方法 创建空物体 为对象 动态添加…...

软件测试面试题-自测

一、测试流程 1.项目测试流程你是怎么开展的&#xff1f; ①首先&#xff0c;需求分析阶段&#xff0c;分析需求点&#xff0c;需求确定以后进入测试计划阶段&#xff0c;参考需求规格说明书进行测试计划编写 ②接着&#xff0c;进入测试设计阶段&#xff0c;依据需求文档及原…...

深度学习-神经网络

文章目录 一、基本组成单元&#xff1a;神经元二、神经网络层三、偏置与权重四、激活函数1.激活函数的作用2.常见的激活函数1).Sigmoid2).Tanh函数3).ReLU函数 五、优点与缺点六、总结 神经网络&#xff08;Neural Network, NN&#xff09;是一种模拟人类大脑工作方式的计算模型…...

Redis - 集群篇 - 集群模式

面试的时候被人问到集群的问题&#xff0c;搬砖仔哪懂这么多&#xff0c;继续整理一下知识点 Redis 集群模式 Redis集群就是将多个Redis节点连接在一起&#xff0c; 让Redis在不同的节点上同时提供服务。 Redis集群主要有三种模式&#xff1a; 主从复制模式&#xff08;mast…...

Robot Operating System——线速度和角速度

大纲 应用场景1. 移动机器人控制场景描述具体应用 2. 无人机控制场景描述具体应用 3. 机械臂运动控制场景描述具体应用 4. 自动驾驶车辆控制场景描述具体应用 5. 机器人仿真场景描述具体应用 6. 机器人传感器数据处理场景描述具体应用 定义字段解释 案例 geometry_msgs::msg::T…...

量化投资策略_因子打分选股的案例实现

一&#xff1a;因子打分选股的介绍 因子打分选股是一种量化投资策略&#xff0c;它通过选取多个与股票收益率相关的因子&#xff0c;对股票进行综合评分&#xff0c;然后根据评分来选择股票构建投资组合。以下是构建多因子打分选股模型的一般步骤&#xff1a; 数据预处理&…...

架构师知识梳理(七):软件工程-工程管理与开发模型

软件工程概述 软件开发生命周期 软件定义时期&#xff1a;包括可行性研究和详细需求分析过程&#xff0c;任务是确定软件开发工程必须完成的总目标&#xff0c;具体可分成问题定义、可行性研究、需求分析等。软件开发时期&#xff1a;就是软件的设计与实现&#xff0c;可分成…...

bp的模块被隐藏了

看我们现在没有代理那个模块了 我们点击查看 这里有被我们隐藏的模块&#xff0c;比如代理等&#xff0c;把前面的眼睛点一下 这个模块就出来了&#xff0c;如果想把他固定在任务栏里 拖动这个位置 就好了&#xff0c;如果有其他问题可以留言&#xff0c;看到可进我的努力给你…...

C++学习笔记(21)

243、条件变量-生产消费者模型 条件变量是一种线程同步机制。当条件不满足时&#xff0c;相关线程被一直阻塞&#xff0c;直到某种条件出现&#xff0c;这些线 程才会被唤醒。 C11 的条件变量提供了两个类&#xff1a; condition_variable&#xff1a;只支持与普通 mutex 搭配&…...