2025-7-23专题训练总结
开题顺序:。
难度顺序:。
A
用时: 分钟。
罚时:。
思路:
由于 很小,所以可以暴力枚举。方程为 ,解出 ,判断 是否等于 即可。
代码:
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL a = 1, c, r = 1e18;
LL C(LL x) {
LL s = 0;
for (; x; s += x % 10, x /= 10);
return s;
}
int main() {
cin >> c, c = -c;
for (LL b = 0; b <= 100; b++) {
LL d = b * b - 4 * a * c, v = sqrt(d);
if (v * v != d) continue;
if (-b + v <= 0 || (-b + v) % (2 * a)) continue;
LL x = (-b + v) / (2 * a);
C(x) == b && (r = min(r, x));
}
cout << (r != 1e18 ? r : -1);
return 0;
}B
用时: 分钟。
罚时:。
:没有考虑金字塔填不满。
: 的最小值设错。
思路:
二分答案。
要使 处的枕头最多,一定是向两边呈金字塔分布。
分类讨论一下,是否可以用金字塔填满。用等差数列求和公式即可算出答案。
代码:
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL n, m, k;
bool C(LL c) {
LL s = 0;
s += c > n - k + 1 ? (c + c - (n - k)) * (n - k + 1) / 2 : (c + 1) * c / 2 + n - k + 1 - c;
s += c > k ? (c - 1 + c - k + 1) * (k - 1) / 2 : (c - 1) * c / 2 + k - c;
return s <= m;
}
int main() {
cin >> n >> m >> k;
LL l = 0, r = m + 1;
for (LL o; l + 1 < r;)
C(o = l + r >> 1) ? l = o : r = o;
cout << l;
return 0;
}呃式子写的有点长其实可以更长。
C
用时: 小时(没开 unsigned long long,最后还是 wyy 大佬调出来的)。
罚时:。
:没开
unsigned long long。
思路:
二分答案。
二分工作时长 ,则第 个机器生产的文件数量为 。判断 是否超过 即可。
代码:
#include <bits/stdc++.h>
using namespace std;
using LL = unsigned long long;
const int N = 105;
LL t, n, k;
array<LL, 3> a[N];
bool C(LL s) {
LL c = 0;
for (int i = 1; i <= n; i++) {
auto [t, l, w] = a[i];
c += s / (t * l + w) * l + min((s % (t * l + w)) / t, l);
}
return c >= k;
}
int main() {
for (cin >> t; t; t--) {
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i][0] >> a[i][1] >> a[i][2];
LL l = 0, r = 9e18;
for (LL o; l + 1 < r;)
C(o = l + r >> 1) ? r = o : l = o;
cout << r << "\n";
}
return 0;
}D
用时: 分钟。
罚时:。
思路:
周期问题,计算一个周期内能烤几分钟,然后就做完了。
代码:
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL k, d, t, n, r;
int main() {
cin >> k >> d >> t, n = ((k - 1) / d + 1) * d, r = 2 * t % (n + k);
cout << fixed << setprecision(9) << 2 * t / (n + k) * n + (r <= 2 * k - 1 ? r / 2.0 : r - k);
return 0;
}E
用时: 分钟。
罚时:。
思路:
二分答案。
太板了,没什么好说的了。
代码:
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 1e5 + 5;
int n, m, t[N];
LL a[N], b[N], c[N];
bool C(int k) {
LL x = 0, y = 0;
copy(a + 1, a + m + 1, b + 1);
for (int i = 1; i <= k; i++) b[t[i]] -= c[i];
for (int i = 1; i <= m; i++)
x += max(b[i], 0ll) / 3 * 3, y += max(-b[i], 0ll);
return x >= 3 * y;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> t[i] >> c[i];
int l = -1, r = n + 1;
for (int o; l + 1 < r;)
C(o = l + r >> 1) ? l = o : r = o;
cout << l;
return 0;
}G
用时: 分钟。
罚时:。
思路:
二分答案。
二分最大距离,算出每个圆与直线的交点区间,判断是否有交集即可。
设点 ,直线 ,圆 。
可以列出方程:解出来即可。
代码:
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 1e5 + 5;
int t, n, a, b, c;
pair<int, int> p[N];
bool C(double d, double k, double h) {
double l = -1e9, r = 1e9;
for (int i = 1; i <= n; i++) {
auto [x, y] = p[i];
double a = k * k + 1, b = 2 * k * h - 2 * x - 2 * k * y, c = x * x + y * y - 2 * h * y + h * h - d * d;
double d = sqrt(b * b - 4 * a * c);
double x1 = (-b - d) / (2 * a), x2 = (-b + d) / (2 * a);
l = max(l, x1), r = min(r, x2);
}
return l <= r;
}
bool C(double d, double h) {
double l = -1e9, r = 1e9;
for (int i = 1; i <= n; i++) {
auto [x, y] = p[i];
double b = -2 * y, c = x * x - 2 * x * h + h * h + y * y - d * d;
double d = sqrt(b * b - 4 * c);
double x1 = (-b - d) / 2, x2 = (-b + d) / 2;
l = max(l, x1), r = min(r, x2);
}
return l <= r;
}
int main() {
for (cin >> t; t; t--) {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> p[i].first >> p[i].second;
cin >> a >> b >> c;
if (!b) {
double h = -c * 1.0 / a, l = 0, r = 1e9;
for (int i = 1; i <= n; i++)
l = max(l, fabs(p[i].first - h));
for (double o; r - l > 1e-7;)
C(o = (l + r) / 2, h) ? r = o : l = o;
cout << fixed << setprecision(7) << r << "\n";
} else {
double k = -a * 1.0 / b, h = -c * 1.0 / b;
double l = 0, r = 1e9;
for (int i = 1; i <= n; i++) {
auto [x, y] = p[i];
l = max(l, fabs(k * x - y + h) / sqrt(k * k + 1));
}
for (double o; r - l > 1e-7;)
C(o = (l + r) / 2, k, h) ? r = o : l = o;
cout << fixed << setprecision(7) << r << "\n";
}
}
return 0;
}需要特判 的情况。
H
用时: 分钟。
罚时:。
思路:
二分答案。
二分最大不满意值 ,则第 座城市可容纳 。
若 且 ,则有解。
代码:
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 2e5 + 5;
int t, n, a[N];
LL b[N], c[N], d[N], w;
bool C(LL v) {
LL s = 0;
for (int i = 1; i <= n; i++) s += (d[i] = v / c[i]);
for (int i = 1; i <= n; i++)
if (s - d[a[i]] < b[i]) return 0;
return s >= w;
}
int main() {
for (cin >> t; t; t--) {
cin >> n, w = 0;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i], w += b[i];
for (int i = 1; i <= n; i++) cin >> c[i];
LL l = -1, r = 1e18;
for (LL o; l + 1 < r;)
C(o = l + r >> 1) ? r = o : l = o;
cout << r << "\n";
}
return 0;
}I
用时: 分钟。
罚时:。
:
pow函数使用 STL 导致 TLE。
:将错误 修改后忘测样例,导致 RE。
思路:
二分答案。
- 计算 年到哪一年有 个平年,可以二分目标年份。
- 计算 到 年的平年数量和 的关系,可以计算 到 年的平年数量和 的关系( 到 年有 个平年)。
- 到 年的闰年数量为
代码:
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL t, k, p[10];
bool C(LL n) {
LL m = 0;
for (int i = 0; i <= 8; i++)
m += n / (4 * p[i]) - n / p[i + 1];
return n - m >= k;
}
int main() {
for (int i = p[0] = 1; i <= 9; i++) p[i] = p[i - 1] * 100;
for (cin >> t; t; t--) {
cin >> k, k += 1533;
LL l = k, r = 2 * k + 1;
for (LL o; l + 1 < r;)
C(o = l + r >> 1) ? r = o : l = o;
cout << r << "\n";
}
return 0;
}






