且歌且行,眉目轻盈。何妨吟啸且徐行。|

胖柚の工作室

园龄:2年1个月粉丝:2关注:15

2024-08-27 14:46阅读: 4评论: 0推荐: 0

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

前置知识及例题:

约数个数定理:
假设一个数为 x,它可以表示为 p1a1×p2a2×...×pkak ,那么它的约数个数就为 i=1k(ai+1)

例如 360 = 23×32×5,那么 2 的个数有 4 种选择(选 0 个,选 1 个,选 2 个,选 3 个),3 的个数有 3 种选择,5 的个数有 2 种选择,因为是相互独立的,所以根据乘法原理,得到432=24

例题:质因子分解
2n 分别求质因子,不需要判断是否为质数,因为每个质因子我们都一直除,直到不能再除,以后也不会出现可以除的数是此数的倍数了,相当于已经筛掉了。

#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

贪心。 唯一需要注意的是 min 的两个参数需要类型一致,因此需要开 long long.

#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 中国大陆许可协议进行许可。

posted @   胖柚の工作室  阅读(4)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起