题解:P15086 [UOI 2025 II Stage] A+B=C
前言
下文均采用 C++23 的标准。
洛谷题目
思路
一眼看去没思路,第二眼看去发现暴力不会 TLE,选择直接暴力枚举。
解法
记
我们考虑枚举
时间复杂度分析
枚举只需枚举
代码
#define ups(i,st,nd) for(int i=(st);i<(nd);++i)
int seg[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int a, b, c, s;
signed main() {
ios::sync_with_stdio(false), ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); clock_t timr_start = clock();
read(a, b, c), s = seg[a] + seg[b];
ups(x, 0, 10) {
int y = c - x;
if (y < 0 || y > 9) continue;
if (seg[x] + seg[y] == s) {
write("Yes");
return 0;
}
}
write("No");
cerr << "time use " << (clock() - timr_start) << "ms.";
return 0;
}
评价
难度大概在红和橙的过度,可以给刚学枚举的同学练习。