AISing Programming Contest 2021(AtCoder Beginner Contest 202) 简单题解记录
补题链接:Here
A - Three Dice
水题,问给定三次摇色子的正面,请问3次结果以后相对面的点数和
cout << (21 - a - b - c) << "\n";
B - 180°
水题,首先反转字符串,然后遇到 6
或者9
则相互替代即可
void solve() {
string s;
cin >> s;
reverse(s.begin(), s.end());
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '6')s[i] = '9';
else if (s[i] == '9')s[i] = '6';
}
cout << s;
}
C - Made Up
给定三个数组,请问有多少种组合使得 \(A_i = B_{c_i}\)
简单的数组存数问题
int a[1 << 17], b[1 << 17];
void solve() {
int n; cin >> n;
for (int i = 1, x; i <= n; ++i) {
cin >> x;
a[x]++;
}
for (int i = 1; i <= n; ++i)cin >> b[i];
ll ans = 0;
for (int i = 1, x ; i <= n; ++i) {
cin >> x;
ans += a[b[x]];
}
cout << ans;
}
D - aab aba baa
一开始没想到 DP 辅助,写了半天的纯组合问题
ll dp[61][61];
void solve() {
int a, b; ll k;
cin >> a >> b >> k;
dp[0][0] = 1;
for (int i = 1; i <= a + b; ++i)
for (int j = 0; j <= i; ++j)
dp[i][j] = dp[i - 1][j] + (j ? dp[i - 1][j - 1] : 0);
a += b;
ll ans = 1;
while (a--) {
auto x = dp[a][b];
if (k < ans + x) cout << 'a';
else cout << 'b', ans += x, b--;
}
cout << "\n";
}