2025-9-27模拟赛总结
前言
cs出题人!下次不许再出数学题了!😡
A、B出题人:tyk
C、D出题人:lyt
成绩:
A
看起来很简单的一道题,实际上一点也不简单(
将一条限制视为一条
还有这几种无解情况:
- 出现环。
- 一个点连两个点。
- 两个点连一个点。
直接用并查集处理一下即可,虽然我也不知道为什么我只有 95 分😐
出题人还是太超标了,下次直接消极怠工好吧(
::::success[正确代码]
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 2e5 + 5, M = 1e9 + 7;
LL n, m, f[N], s;
map<pair<int, int>, bool> k;
int R(int x) {
return f[x] == x ? x : f[x] = R(f[x]);
}
int main() {
cin >> n >> m, s = n;
iota(f + 1, f + n + 1, 1);
for (int i = 1, x, y; i <= m; i++) {
cin >> x >> y;
if (R(x) != R(y)) s--, f[R(x)] = R(y);
else if (!k[{x, y}]) cout << 0, exit(0);
k[{x, y}] = 1;
}
for (LL i = s - 1; i; i--) s = s * i % M;
cout << s;
return 0;
}
::::
B
cs题目,cs出题人,再出把你吃了。
😁推了 1h 式子无果😐,找了 1h 规律没用😑,摆了 1h 还是不会😶。
最终还是拼尽全力无法战胜了😭😭😭
只好写了
::::error[代码]
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 1e6 + 5, M = 1e9 + 7;
LL t, n, m, k, a[N], b[N], c[N];
void S(int x) {
if (x > k) {
copy(a + 1, a + k + 1, b + 1);
sort(b + 1, b + k + 1);
c[unique(b + 1, b + k + 1) - b - 1]++;
return;
}
for (int i = 1; i <= n; i++) a[x] = i, S(x + 1);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
for (cin >> t; t; t--) {
cin >> n >> m;
if (n == 1) {
cout << (m * 2 + 1) % M << "\n";
} else {
fill(c, c + m + 1, 0), c[0] = 1;
for (k = 1; k <= m; k++) S(1);
int s = 0;
for (int i = 0; i <= m; i++)
s = (s + c[i] * (i + 1) % M) % M;
cout << s << "\n";
}
}
return 0;
}
::::
正解:饿啊!题解被外星人吃掉了!
经过若干年推出来的公式:
::::success[正确代码]
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int M = 1e9 + 7;
LL t, n, m;
LL P(LL x, LL y) {
LL r = 1;
for (; y; x = x * x % M, y >>= 1) y & 1 && (r = r * x % M);
return r;
}
LL C(LL x, LL y) {
return !x ? 1 : (x == 1 ? (y + 1) % M : (P(x, y + 1) - 1 + M) % M * P(x - 1, M - 2) % M);
}
int main() {
for (cin >> t; t; t--) {
cin >> n >> m;
cout << (((C(n, m) + C(n, m + 1)) % M - 1 + M) % M - n * C(n - 1, m) % M + M) % M << "\n";
}
return 0;
}
::::
C
最后
我直接暴力
::::error[代码]
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 5005;
LL n, a[N], b[N], f[N][N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
fill(f[1], f[1] + n + 1, -1e18);
f[1][0] = 0, f[1][1] = b[1] - a[1];
for (int i = 2; i <= n; i++)
for (int j = 0; j <= n; j++)
f[i][j] = max({j ? f[i - 1][j - 1] : 0ll, f[i - 1][j], f[i - 1][j + 1]}) + j * (b[i] - a[i]);
cout << max(f[n][0], f[n][1]);
return 0;
}
::::
正解
::::success[正确代码]
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 1e6 + 5;
LL n, p[N], s;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 1, a, b; i <= n; i++)
cin >> a >> b, p[i] = p[i - 1] + b - a;
priority_queue<LL, vector<LL>, greater<LL>> q;
q.push(0);
for (int i = 1; i <= n; i++) {
p[i] > q.top() && (s += p[i] - q.top(), q.pop(), q.push(p[i]), 1);
q.push(p[i]);
}
cout << s;
return 0;
}
::::
D
没有时间了,不过评测机有时间🤣
时间限制 5s 🤔
20 个测试点 🤔
哈哈哈哈哈哈😏 评测机!加油!💪
::::warning[代码]
#include <bits/stdc++.h>
using namespace std;
unsigned __int128 rp = 1;
int main() {
for (int i = 0; i <= 100; i *= 2, rp += rp) {
cout << "t\by\bk\b \bi\b \bl\bo\bv\be\b \by\bo\bu\b \b";
cout << "fkurmom\b\b\b\b\b\b\b";
}
return 0;
}
::::
后记
下次一定不能这样了😭不能这么菜了。