AtCoder Beginner Contest 421
文章目录
- A Misdelivery
- B Fibonacci Reversed
- C Alternated
- D RLE Moving
- E Yacht
- F Erase between X and Y
- G Increase to make it Increasing
AtCoder Beginner Contest 421
A Misdelivery
Mansion AtCoder has N rooms numbered from room 1 to room N.
Each room i is inhabited by one person named Si.
You are to deliver a package addressed to Mr./Ms. Y in room X. Determine whether the destination is correct.
翻译:
AtCoder 公寓有 N 个房间,编号从 1 到 N。
每个房间 i 都住着一位名叫 Si 的人。
你需要将一个包裹送到 X 房间的 Y 先生/女士手中。请确认收件人地址是否正确。
分析:判断数组 a[x] 是否为 y。
#include <bits/stdc++.h>
using namespace std;void solve() {int n; cin >> n;vector<string> s;string x;for (int i = 1; i <= n; i++)cin >> x, s.push_back(x);int p; cin >> p >> x;cout << (s[p - 1] == x ? "Yes" : "No") << "\n";
}
int main() {int T = 1; while (T--) solve();return 0;
}
B Fibonacci Reversed
#include <bits/stdc++.h>
using ll = long long;
using namespace std;ll f(int a) {string s = to_string(a);reverse(s.begin(), s.end());return atoll(s.c_str());
}
void solve() {ll x, y; cin >> x >> y;vector<ll> a({0, x, y});for (int i = 3; i <= 10; i++)a.push_back(f(a[i - 1] + a[i - 2]));cout << a[10] << "\n";
}
signed main() {int T = 1; while (T--) solve();return 0;
}
C Alternated
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int N = 1e6 + 5;
vector<int> a(N), tmp(N);
void msort(int l, int r, ll& cnt) {if (l >= r) return;int mid = l + r >> 1, i = l, j = mid + 1, p = 0;msort(l, mid, cnt), msort(mid + 1, r, cnt);while (i <= mid && j <= r) {if (a[i] <= a[j]) tmp[++p] = a[i++];else tmp[++p] = a[j++], cnt += mid - i + 1ll;}while (i <= mid) tmp[++p] = a[i++];while (j <= r) tmp[++p] = a[j++];for (int i = 1; i <= p; i++) a[l++] = tmp[i];
}
void solve() {int n; string s;cin >> n >> s, n *= 2;int x = 1, y = 2;for (int i = 0; i < n; i++) {if (s[i] == 'A') a[i + 1] = x, x += 2;else a[i + 1] = y, y += 2;}ll cnt1 = 0, cnt2 = 0;msort(1, n, cnt1);x = 2, y = 1;for (int i = 0; i < n; i++) {if (s[i] == 'A') a[i + 1] = x, x += 2;else a[i + 1] = y, y += 2;}msort(1, n, cnt2);cout << min(cnt1, cnt2) << "\n";
}
signed main() {int T = 1; while (T--) solve();return 0;
}