AtCoder Beginner Contest 428

news/2025/10/18 22:23:18/文章来源:https://www.cnblogs.com/maburb/p/19150229

A - Grandma's Footsteps

题意:总共\(x\)秒,每\(a\)秒每秒跑\(s\)米,然后停止\(b\)秒。如此循环求总共跑多少秒。

模拟即可。

点击查看代码
#include <bits/stdc++.h>using i64 = long long;void solve() {int s, a, b, x;std::cin >> s >> a >> b >> x;int ans = 0;int t = 0;while (t <= x) {int c = std::min(x - t, a);ans += c * s;t += c;t += b;}std::cout << ans << "\n";
}int main() {std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);int t = 1;// std::cin >> t;while (t -- ) {solve();}return 0;
}

B - Most Frequent Substrings

题意:一个字符串,求每个长度为\(k\)的子串出现了多少次,然后求最大次数以及出现次数最大的使用子串。

每个子串求一个出现次数就行。

点击查看代码
#include <bits/stdc++.h>using i64 = long long;void solve() {int n, k;std::cin >> n >> k;std::string s;std::cin >> s;std::map<std::string, int> mp;for (int i = 0; i + k - 1 < n; ++ i) {std::string t = s.substr(i, k);int cnt = 0;for (int j = 0; j + k - 1 < n; ++ j) {if (t == s.substr(j, k)) {++ cnt;}}mp[t] = std::max(mp[t], cnt);}std::vector<std::string> ans;int max = 0;for (auto & [t, cnt] : mp) {if (cnt > max) {ans.clear();ans.push_back(t);max = cnt;} else if (cnt == max) {ans.push_back(t);}}std::cout << max << "\n";for (auto & t : ans) {std::cout << t << " \n"[t == ans.back()];}
}int main() {std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);int t = 1;// std::cin >> t;while (t -- ) {solve();}return 0;
}

C - Brackets Stack Query

题意:每次加左括号或者右括号,或者删除最后一个括号。求每次操作后是不是合法括号序列。

括号序列要合法,记左括号为\(1\)右括号为\(-1\),那么每个位置前缀和都大于等于\(0\)且最后和为\(0\)。那么记录一下前缀和,把小于\(0\)的位置记一下。每次要每次小于\(0\)的位置且最后和为\(0\)才合法。

点击查看代码
#include <bits/stdc++.h>using i64 = long long;void solve() {int Q;std::cin >> Q;std::vector<int> a(Q + 1);int p = 0;std::set<int> s;while (Q -- ) {int op;std::cin >> op;if (op == 1) {char c;std::cin >> c;if (c == '(') {a[p + 1] = a[p] + 1;++ p;} else {a[p + 1] = a[p] - 1;++ p;}if (a[p] < 0) {s.insert(p);}} else {if (a[p] < 0) {s.erase(p);}-- p;}if (s.empty() && a[p] == 0) {std::cout << "Yes\n"; } else {std::cout << "No\n";}}
}int main() {std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);int t = 1;// std::cin >> t;while (t -- ) {solve();}return 0;
}

D - 183184

题意:给你\(C, D\),求有多少\(f(C, C + x)\)是平方数,其中\(x \in [1, D]\)\(f(a, b)\)\(a\)后面拼接\(b\)构成的数字。

\(f(C, X)\) = \(C \times 10^t+ X\),其中\(t\)\(X\)的位数,\(X \in [C + 1, C + D]\)。那,那么对于一个\(t\)\(X \in [\max(C + 1, 10^{t-1}, \min(C + D, 10^t - 1]\),则\(k^2 \in [C \times 10^t + \max(C + 1, 10^{t-1}, C \times 10^t + \min(C + D, 10^t - 1]\)\(k \in [\lceil \sqrt{C \times 10^t + \max(C + 1, 10^{t-1}} \rceil, \lfloor \sqrt{C \times 10^t + \min(C + D, 10^t - 1} \rfloor]\)。枚举\(t\)即可。

点击查看代码
#include <bits/stdc++.h>using i64 = long long;i64 floor(i64 x) {i64 r = sqrtl((long double)x);while ((r + 1) > 0 && (r + 1) * (r + 1) <= x) {++ r;}while (r > 0 && r * r > x) {-- r;}return r;
}i64 ceil(i64 x) {i64 r = floor(x);if (r * r < x) {++ r;}return r;
}int get(i64 n) {int d = 0;while (n) {n /= 10;++ d;}return std::max(d, 1);
}void solve() {i64 p10[20]{};p10[0] = 1;for (int i = 1; i < 20; ++ i) {p10[i] = p10[i - 1] * 10;}i64 C, D;std::cin >> C >> D;i64 ans = 0;i64 L = C + 1;i64 R = C + D;int x = get(L);int y = get(R);for (int t = x; t <= y; ++ t) {i64 lo = std::max(L, p10[t - 1]);i64 hi = std::min(R, p10[t] - 1);if (lo > hi) {continue;}i64 base = C * p10[t];i64 klo = ceil(base + lo);i64 khi = floor(base + hi);if (klo <= khi) {ans += (khi - klo + 1);}}std::cout << ans << "\n";
}int main() {std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);int t = 1;std::cin >> t;while (t -- ) {solve();}return 0;
}

E - Farthest Vertex

题意:一棵树,求距离每个最远的点是哪个,有多个选编号最大的。

经典结论,树上距离一个点最优的点一定是一条直径的端点。
那么可以求距离\(1\)最远最大的端点,然后求离这个点最远最大点,就知道了距离一个点的直径两端最大的点。然后比较一下距离。

点击查看代码
#include <bits/stdc++.h>using i64 = long long;void solve() {int n;std::cin >> n;std::vector<std::vector<int>> adj(n);for (int i = 1; i < n; ++ i) {int u, v;std::cin >> u >> v;-- u, -- v;adj[u].push_back(v);adj[v].push_back(u);}auto bfs = [&](int s, std::vector<int> & d) -> int {std::queue<int> q;	std::fill(d.begin(), d.end(), -1);q.push(s);d[s] = 0;while (q.size()) {int u = q.front(); q.pop();for (auto & v : adj[u]) {if (d[v] == -1) {d[v] = d[u] + 1;q.push(v);}}}int res = 0;for (int i = 1; i < n; ++ i) {if (d[i] >= d[res]) {res = i;}}return res;};std::vector<int> d1(n), d2(n);int p = bfs(0, d1);int q = bfs(p, d1);bfs(q, d2);for (int i = 0; i < n; ++ i) {if (d1[i] > d2[i]) {std::cout << p + 1 << "\n";} else if (d1[i] < d2[i]) {std::cout << q + 1 << "\n";} else {std::cout << std::max(p, q) + 1 << "\n";}}
}int main() {std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);int t = 1;// std::cin >> t;while (t -- ) {solve();}return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/939795.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

swtich的应用

swtich分支语句 swtich在多种情况下发生一种,下面是swtich的基本方式: 另一种方式:当变量和case相符时,一依次去执行后面语句,除非遇到break为止 下面是模拟四则运算:switch分支结构中比较的必须是整型,字符,不…

2025/10/18

2025/10/18学习算法

模板机制作

虚拟机的模板机制作我以openeuler为例清楚网卡的配置信息清除密钥信息开机会自动生成密钥的清除machine id关闭虚拟机关闭后,不要再开开启了克隆

P14253 旅行(trip)题解 - 符星珞

P14253 旅行(trip)题解题目描述 积云厚重,而卷云飘渺。 小 W 报名了一个为期 \(n\) 天的旅行团。作为一名气象学家,他记录了旅行期间每天的温度,形成一个序列 \(A = (a_1, a_2, \dots, a_n)\)。 小 W 希望从这 \(…

因式分解

好的,我们一起来因式分解这个多项式: \[x^2 - 2y^2 + xy + x + 5y - 2 \] 1. 按 \(x\) 降幂排列并尝试分组 把它看作关于 \(x\) 的二次式: \[x^2 + xy + x - 2y^2 + 5y - 2 \]即: \[x^2 + (y+1)x + (-2y^2 + 5y - …

[Perl]install DateTime module

To install the DateTime module in Perl, you have a few options depending on your system setup. I’ll outline the most reliable and professional methods, starting from the most standard approach.1. Usin…

小马智行 VS 文远知行

目录背景和价值参考资料 背景和价值 比较小马智行和文远知行这两家自动驾驶领域的头部公司,确实需要从多个维度深入分析。它们就像选择了不同赛道的顶尖选手,各有各的策略和优势。为了让你能快速把握全局,我先用一个…

20251018 杂题 总结

DP优化 P2224 [HNOI2001] 产品加工 首先是暴力DP,社fi,j1,j2,第i个物品,A机器j1事件,B机器j2事件,然后直接转移就行了,但是n^3的状态,孬 考虑降维,bool的内容可以改为数值,社fij表示第i个任务,A机器做了j时间…

【做题记录】P9753 [CSP-S 2023] 消消乐

题目链接 这道题状态设计十分巧妙。 直接转移显然不切实际。我们不妨“消消乐”的性质入手: 如果区间 \([i,j],[j+1,k]\) 都是可消除的,那么 \([i,k]\) 一定也是可消除的。根据此性质,我们设置辅助数组 \(g\) 维护当…

[Linux] homebrew MacOS和Linux下的软件管理工具

[Linux] homebrew MacOS和Linux下的软件管理工具$(".postTitle2").removeClass("postTitle2").addClass("singleposttitle");目录01 安装下载02 使用homebrew2.1 安装和卸载2.2 搜索与信…

nas webdav 挂载盘Git报错:fatal: detected dubious ownership in repository at - 何苦

nas webdav 挂载盘Git报错:fatal: detected dubious ownership in repository at场景描述,在nas220+中用web station部署php项目 项目目录指向web项目根目录,本地电脑用webdav挂载web项目根目录,用git拉nas部署的g…

题解:P14254 分割(divide)

题目: 有交且 \(b_1\) 深度最小,我们要选 \(k\) 个点深度相同的点。 手玩样例发现选点的时候我们被子树内最深深度限制,称 \(x\) 子树内最深深度为 \(h_x\)。 把每层的点拎出来: \(b_1\) 和 \(1\) 为根的点很特殊,…

学生信息管理系统(DAO模式重构)项目报告

学生信息管理系统(DAO 模式重构)项目报告目录学生信息管理系统(DAO 模式重构)项目报告一、项目概述1.1 项目功能介绍1.2 原项目结构1.3 原项目不足1.4 改造方向1.5 改造后的优势二、项目分析2.1 结构解析2.1.1 DAO…

思科公司分析

目录背景和价值参考资料 背景和价值 对于您这样保守的投资人来说,思科确实呈现出一个值得仔细权衡的投资画像:它像一艘财务稳健、拥有宽阔护城河的航母,但航速可能不如那些新兴的科技快艇。下面,我将结合您提出的六…

桃星中央关于重大去向问题的初步决定

桃星中央关于重大去向问题的初步决定 经过参谋部汇总各方民意,最终根据中央定下的“最好不过江,中原附近”的标准,以及考虑到院校实力和自身情况,最终决定重大去向问题的初步结果: 北京市 上海市 江苏省南京市 湖…

Google Deepmind 宣布与 CFS 合作开发核聚变

Google Deepmind 宣布与 CFS 合作开发核聚变 2025 年 10 月 16 日,Google DeepMind 和 Commonwealth Fusion Systems (CFS) 共同宣布建立研究合作伙伴关系,将 AI 全面引入下一代聚变能源的设计和运行中。Commonwealt…

开源嵌入模型对比:让你的RAG检索又快又准

嵌入(Embedding)是RAG流程里非常关键的一个步骤。它处理的是数据提取和分块之后的内容,嵌入的好坏直接影响系统能不能准确地表示和检索信息。这篇文章会讲清楚嵌入是什么、怎么工作的,还有怎么挑选合适的模型。 经…

C++lambda表达式简单笔记

lambda表达式lambda表达式语法#include <iostream>int main(int argc, char* argv[]) {/*** 1. 基本形式与语法*///如果没有传入参数,参数列表可以省略auto lambda1 = []() { std::cout << "Hello, …

智慧城市基础设施漏洞分析与国家安全影响

本文深入分析智慧城市基础设施中的安全漏洞,涵盖智能交通系统、智能电网、智能监控系统和水务管理系统的具体漏洞技术细节,提供概念验证脚本和缓解策略,旨在提升对国家安全至关重要的城市环境网络安全防护能力。智慧…