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

【码蹄杯】2025年本科组省赛第一场

在这里插入图片描述

个人主页:Guiat
归属专栏:算法竞赛

在这里插入图片描述

文章目录

  • 1. MC0455 · 四大名著-西游签到
  • 2. MC0456 · 斩断灵藤
  • 3. MC0457 · 符咒封印
  • 4. MC0458 · 移铁术
  • 5. MC0459 · 昆仑墟
  • 6. MC0460 · 星空迷轨阵
  • 7. MC0461 · 排队
  • 8. MC0462 · 最后一难

正文

总共8道题。

1. MC0455 · 四大名著-西游签到

【题目】 MC0455 · 四大名著-西游签到

【AC_Code】

#include <bits/stdc++.h>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);using namespace std;const int N = 2e4 + 10; char s[N], t[N];void solve()
{int T; cin >> T;while (T --){cin >> s + 1 >> t + 1;int l = 1, r = strlen(s + 1);while (l < r && s[l] == t[l]) l ++;while (l < r && s[r] == t[r]) r --;int len = r - l + 1, check = 1;for (int i = 0; i < len; i ++) if (s[l + i] != t[r - i]) check = 0;if (check) cout << "Y\n"; else cout << "N\n"; }
}int main()
{IOS int _ = 1;   // cin >> _;while (_ --) solve(); return 0;
}

2. MC0456 · 斩断灵藤

【题目】MC0456 · 斩断灵藤

【AC_Code】

#include <bits/stdc++.h>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);using namespace std;void solve()
{int n, m; cin >> n >> m; vector<vector<int>> c(n);for (int i = 0; i < n - 1; i ++){int u, v; cin >> u >> v; u --; v --;c[u].push_back(v); c[v].push_back(u);}function<int(int, int)> s; int ans = 0;s = [&](int h, int i){vector<int> k;for (int l : c[h]){if (l == i) continue;int m = s(l, h); k.push_back(m);}sort(k.begin(), k.end());int a = 1;for (int p : k){if (a + p > m && p > 0) ans ++;else if (a + p <= m) a += p;}return a;};if (s(0, -1) > 0) ans += (1 * 1);cout << ans << '\n';
}int main()
{IOS int _ = 1;   // cin >> _;while (_ --) solve(); return 0;
}

3. MC0457 · 符咒封印

【题目】MC0457 · 符咒封印

【AC_Code】

#include <bits/stdc++.h>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);using namespace std;
using ll = long long;const int N = 5e5 + 10, mod = 998244353;
ll a[N], b[N], c[N], ans;void solve()
{int n, q; cin >> n >> q;for (int i = 1; i <= n; i ++){cin >> a[i];b[i] = (b[i - 1] + a[i]) % mod;c[i] = (c[i - 1] + a[i] * i) % mod;}while (q --){int l, r; cin >> l >> r;ll x = c[r] - c[l - 1], y = b[r] - b[l - 1], z = (l - 1) * y;ans = (x - z) % mod; ans = (ans + mod) % mod; cout << ans << '\n';}
}int main()
{IOS int _ = 1;   // cin >> _;while (_ --) solve(); return 0;
}

4. MC0458 · 移铁术

【题目】MC0458 · 移铁术

【AC_Code】


5. MC0459 · 昆仑墟

【题目】MC0459 · 昆仑墟

【AC_Code】


6. MC0460 · 星空迷轨阵

【题目】MC0460 · 星空迷轨阵

【AC_Code】


7. MC0461 · 排队

【题目】MC0461 · 排队

【AC_Code】

#include <bits/stdc++.h>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);using namespace std;void solve()
{int T; cin >> T;while (T --){int n; cin >> n; vector<int> a[n + 1]; priority_queue<int> q;for (int i = 1; i <= n; i ++){int opt; cin >> opt; int x, y;if (opt == 1) { cin >> x; y = n - 1; }else if (opt == 2) { cin >> y; x = 0; }else cin >> x >> y;swap(x, y); x = n - x; y = n - y; a[x].push_back(y);}int ans = 1;for (int i = 1; i <= n; i ++){for (unsigned j = 0; j < a[i].size(); j ++) q.push(-a[i][j]);if (q.empty()) { ans = 0; break; }int x = -q.top(); q.pop();if (x < i) { ans = 0; break; }}cout << (ans ? 'Y' : 'N') << '\n';}
}int main()
{IOS int _ = 1;   // cin >> _;while (_ --) solve(); return 0;
}

8. MC0462 · 最后一难

【题目】MC0462 · 最后一难

【AC_Code】

#include <bits/stdc++.h>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);using namespace std;size_t t = 0; int ans = 0;void solve()
{string s; cin >> s;while ((t = s.find("matiji", t)) != string :: npos) { t += 5; ans ++; }cout << ans << '\n';
}int main()
{IOS int _ = 1;   // cin >> _;while (_ --) solve(); return 0;
}

结语
感谢您的阅读!期待您的一键三连!欢迎指正!

在这里插入图片描述

http://www.xdnf.cn/news/18732.html

相关文章:

  • 【Linux系统】命名管道与共享内存
  • 硬件笔记(27)---- 恒流源电路原理
  • [Redis进阶]---------持久化
  • 如何查看MySQL 的执行计划?
  • Spring Boot 3为何强制要求Java 17?
  • JavaScript 性能优化实战技术文章大纲
  • Games 101 第四讲 Transformation Cont(视图变换和投影变换)
  • 深入剖析结构体内存对齐
  • 边缘计算服务器EMI滤波器 故障分析与解决思路
  • 【LeetCode 热题 100】300. 最长递增子序列——(解法一)记忆化搜索
  • C++ 20: Concepts 与Requires
  • 链表-23.合并K个升序链表-力扣(LeetCode)
  • Qt从qmake迁移到cmake的记录
  • Spring Boot 整合网易163邮箱发送邮件实现找回密码功能
  • PHP - 线程安全 - 疑问与答案
  • PyQt6 进阶篇:构建现代化、功能强大的桌面应用
  • uniApp对接实人认证
  • Clustering Enabled Wireless Channel Modeling Using Big Data Algorithms
  • 【前端debug调试】
  • 如何解决pip安装报错ModuleNotFoundError: No module named ‘arviz’问题
  • 网站速度慢?安全防护弱?EdgeOne免费套餐一次性解决两大痛点
  • chapter05_从spring.xml读取Bean
  • 完整实验命令解析:从集群搭建到负载均衡配置
  • Java:类及方法常见规约
  • Unity中删除不及时的问题
  • 牛客面经2 京东社招-002
  • PyTorch框架之图像识别模型与训练策略
  • 25.深入对象
  • 寻找AI——高保真还原设计图生成App页面
  • 华为/思科/H3C/锐捷操作系统操作指南