AtCoder Beginner Contest 052
A - Two Rectangles
#include <bits/stdc++.h> using namespace std; using i64 = long long; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int A, B, C, D; cin >> A >> B >> C >> D; cout << max(A*B, C*D); return 0; }
B - Increment Decrement
#include <bits/stdc++.h> using namespace std; using i64 = long long; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int N, x = 0; string S; cin >> N >> S; int ans = 0; for (int i = 0; i < N; i++) { if (S[i] == 'I') x++; else x--; ans = max(ans, x); } cout << ans; return 0; }
C - Factors of Factorial
前置知识及例题:
约数个数定理:
假设一个数为
例如
例题:质因子分解
从
#include <bits/stdc++.h> using namespace std; using i64 = long long; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int N; cin >> N; vector<int> a(N + 1, 0); for (int i = 2; i <= N; i++) { int t = i; for (int j = 2; j <= i; j++) { while (t % j == 0) { a[j]++; t /= j; } } } for (int i = 1; i <= N; i++) { if (a[i] != 0) cout << i << " " << a[i] << "\n";//先输出底数再输出指数。 } return 0; }
这样看本题就很简单了。
#include <bits/stdc++.h> using namespace std; using i64 = long long; const int mod = 1e9 + 7; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int N; cin >> N; vector<int> a(N + 1, 0); for (int i = 2; i <= N; i++) { int t = i; for (int j = 2; j <= i; j++) { while (t % j == 0) { a[j]++; t /= j; } } } i64 ans = 1; for (int i = 2; i <= N; i++) { if (a[i] != 0) { ans *= (a[i] + 1); ans %= mod; } } cout << ans; return 0; }
D - Walk and Teleport
贪心。 唯一需要注意的是
#include <bits/stdc++.h> using namespace std; using i64 = long long; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); i64 N, A, B; cin >> N >> A >> B; vector<int> x(N); for (int i = 0; i < N; i++) cin >> x[i]; i64 ans = 0; for (int i = 1; i < N; i++) { int d = x[i] - x[i - 1]; ans += min(d * A, B); } cout << ans; return 0; }
本文作者:pangyou3s
本文链接:https://www.cnblogs.com/pangyou3s/p/18382678
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
分类:
标签:
,
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步