ABD 都很简单 C 题 “You don’t have to minimize the number of moves”很关键,一开始没太在意,最后发现正是因为这一点,直接模拟冒泡排序就行了
A - Game with Cards
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
int mxa = -1, mxb = -1;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
mxa = max(mxa, x);
}
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
mxb = max(mxb, x);
}
cout << (mxa >= mxb ? "Alice" : "Bob") << '\n';
cout << (mxb >= mxa ? "Bob" : "Alice") << '\n';
}
return 0;
}
B - Card Trick
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int m;
cin >> m;
vector<int> b(m);
for (int i = 0; i < m; i++) {
cin >> b[i];
}
long long p = accumulate(b.begin(), b.end(), 0ll);
cout << a[p % n] << '\n';
}
return 0;
}
C - Double Sort
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
vector<pair<int, int>> ans;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] < a[j] || (a[i] == a[j] && b[i] < b[j])) {
ans.emplace_back(i, j);
swap(a[i], a[j]);
swap(b[i], b[j]);
}
}
}
if (is_sorted(b.begin(), b.end())) {
cout << (int) ans.size() << '\n';
for (auto &[i, j] : ans) {
cout << i + 1 << ' ' << j + 1 << '\n';
}
} else {
cout << "-1\n";
}
}
return 0;
}
D - Required Length
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
long long x;
cin >> n >> x;
queue<long long> que;
map<long long, int> mp;
que.push(x);
while (!que.empty()) {
auto t = que.front();
que.pop();
string s = to_string(t);
if ((int)s.size() == n) {
cout << mp[t] << '\n';
return 0;
}
for (char &c : s) {
if (c == '0' || c == '1') {
continue;
}
long long v = (c - '0') * t;
if (!mp.count(v)) {
mp[v] = mp[t] + 1;
que.push(v);
}
}
}
cout << "-1\n";
return 0;
}