2025年第八届广西大学生程序设计大赛(热身赛)题解
知乎评价:如何评价2025年第八届GXCPC广西大学生程序设计大赛暨中国-东盟国际大学生程序设计大赛?
题目链接:第八届广西大学生程序设计大赛暨2025邀请赛(热身赛)
题目来源(去年正式赛): 2024年第七届广西大学生程序设计大赛(正式赛)题解
难度 | 签到题 | 普通题 | 中等题 |
---|---|---|---|
题号 | A | B | C D |
情况 | ✔ | ✔ | ✔️ |
全部资料:一至八届 GXCPC广西大学生程序设计竞赛 题目与题解
文章目录
- 签到题
- A. Hello,GXCPC!
- 题目大意:
- 解题思路:
- 参考代码c++:
- 普通题
- B. Epsilon Estuary
- 题目大意:
- 解题思路:
- 官方idea:
- 个人idea:
- 参考代码c++(官方idea):
- 中等题
- C. Dune
- 题目大意:
- 解题思路:
- 参考代码c++:
- D. Hashing Collision
- 题目大意:
- 解题思路:
- 参考代码c++:
签到题
A. Hello,GXCPC!
A.Hello, GXCPC!
你好,GXCPC!
题目大意:
无输入,打印输出 I AK GXCPC!
解题思路:
不需要思路。
参考代码c++:
#include <iostream>
using namespace std;
int main()
{cout << "I AK GXCPC!";
}
普通题
B. Epsilon Estuary
B. Epsilon Estuary
ε河口
题目大意:
有 n 只史莱姆,第 i 只血量是 xi 。
每次史莱姆受到攻击会裂成两个,受到攻击后的血量是 x 的话,会裂成 ⌊x/2⌋ 和 ⌈x/2⌉。
现在你可以使用法术,每次对全场所有史莱姆造成 y 点攻击。
问清场最少需要使用多少次法术。
1 ≤ n ≤ 10 ^ 5, 1 ≤ xi, y ≤ 10 ^ 18
解题思路:
官方idea:
个人idea:
官方题解说得对!找出最大值,再进行处理。
数据规模大,注意读写速度。
参考代码c++(官方idea):
#include<iostream>
using namespace std;
int main() {int t;cin >> t;while (t--) {long long n, y, maxn = 0, cnt = 0;scanf("%lld %lld", &n, &y);while (n--) {long long x;scanf("%lld", &x);maxn = max(maxn, x);}while (maxn > 0) {maxn = (maxn - y + 1) / 2;cnt++;}printf("%lld\n", cnt);}return 0;
}
中等题
C. Dune
C.Dune
沙丘
题目大意:
解题思路:
参考代码c++:
使用deepseek辅助生成
#include<bits/stdc++.h>
using namespace std;#define ll long long
#define all(a) a.begin()+1,a.end()
#define all0(a) a.begin(),a.end()
#define endl '\n'
#define pb(a) push_back(a)struct node{ll a,b,op,len;bool operator < (const node&t)const{if(a*t.b != t.a*b) return a*t.b < t.a*b; else return op < t.op;}
};void solve() {int n, x;cin >> n >> x;vector<node> e;for (int i = 1; i <= n; i++) {ll l, r, v;cin >> l >> r >> v;if (r < x) {e.push_back({x - r, v, 0, r - l});e.push_back({x - l, v, 1, r - l});} else if (l <= x) {e.push_back({0, 1, 0, r - l});e.push_back({x - l, v, 1, r - l});}}sort(all0(e));priority_queue<ll, vector<ll>, greater<ll>> pq;unordered_map<ll, int> del_cnt;ll ans = 0;for (int i = 0; i < (int)e.size(); ++i) {auto [a, b, op, len] = e[i];if (op == 0) {pq.push(len);} else {del_cnt[len]++;}if (i < (int)e.size() - 1) {auto [a1, b1, op1, len1] = e[i + 1];if (a * b1 != a1 * b || op != op1) {// Clean up invalid elementswhile (!pq.empty()) {ll t = pq.top();auto it = del_cnt.find(t);if (it != del_cnt.end() && it->second > 0) {if (--it->second == 0) {del_cnt.erase(it);}pq.pop();} else {break;}}if (!pq.empty()) {ans = max(ans, pq.top());}}}}cout << ans << endl;
}int main() {ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);solve();return 0;
}
D. Hashing Collision
D.Hashing Collision
哈希冲突
题目大意:
解题思路:
参考代码c++:
使用deepseek辅助生成
#include <bits/stdc++.h>
using namespace std;
using ll = long long;int main() {ios::sync_with_stdio(false);cin.tie(0);ll n, p, m;cin >> n >> p >> m;vector<ll> a(n);for (int i = 0; i < n; i++) cin >> a[i];vector<ll> b;b.reserve(n * (n + 1) / 2);for (int i = 0; i < n; i++) {ll h = 0;for (int j = i; j >= 0; j--) {h = (h * p + a[j]) % m;b.push_back(h);}}sort(b.begin(), b.end());ll ans = 0;ll cnt = 1;for (size_t i = 1; i < b.size(); ++i) {if (b[i] == b[i-1]) {++cnt;} else {ans += cnt * (cnt - 1);cnt = 1;}}ans += cnt * (cnt - 1);vector<vector<int>> lcp(n + 1, vector<int>(n + 1, 0));for (int i = n - 1; i >= 0; --i) {for (int j = n - 1; j >= 0; --j) {if (a[i] == a[j]) {lcp[i][j] = lcp[i + 1][j + 1] + 1;} else {lcp[i][j] = 0;}}}ll same_pairs = 0;for (int i = 0; i < n; ++i) {for (int j = i + 1; j < n; ++j) {same_pairs += lcp[i][j];}}ans -= same_pairs * 2;cout << ans << '\n';return 0;
}
ADHJKM题 题解(来自网友)
本篇 C 题对应 这链接 D 题
本篇 D 题对应 这链接 H 题