最大值的下标
AC代码:
#include <bits/stdc++.h> using namespace std; using LL = long long; void Solve() { int n; cin >> n; vector<int> a(n); int ans = 0, tag = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] > ans) { ans = a[i]; tag = i + 1; } } cout << tag << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { Solve(); } return 0; }
构造,分奇数偶数,最大值一定是后两个数的和
AC代码:
#include <bits/stdc++.h> using namespace std; using LL = long long; void Solve() { int n; cin >> n; if (n & 1) { cout << "1 2 3 "; for (int i = n - 2; i >= 4; i--) { cout << i << " "; } cout << n - 1 << " " << n << '\n'; } else { for (int i = n - 2; i >= 1; i--) { cout << i << " "; } cout << n - 1 << " " << n << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { Solve(); } return 0; }
模拟
AC代码:
#include <bits/stdc++.h> using namespace std; using LL = long long; void Solve() { int n; cin >> n; priority_queue<int> a, b; for (int i = 0; i < n; i++) { int x; cin >> x; a.push(x); } for (int i = 0; i < n; i++) { int x; cin >> x; b.push(x); } int ans = 0; while (!a.empty() and !b.empty()) { int x = a.top(), y = b.top(); a.pop(), b.pop(); if (x == y) { continue; } else { ans++; if (x > y) { int z = 0; while (x) { z++; x /= 10; } a.push(z); b.push(y); } else {//y > x int z = 0; while (y) { z++; y /= 10; } a.push(x); b.push(z); } } } cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { Solve(); } return 0; }
区间DP,或者模拟,还没想出来为什么QAQ,为什么Bob不赢!hack:abcoaczcba?
AC代码:
#include <bits/stdc++.h> using namespace std; using LL = long long; void Solve() { string s; cin >> s; int len = s.size(); int i = 0, j = len - 1; while (i < j) { if (s[i] == s[j]) { i++, j--; } else { break; } } while (i < j) { if (s[i] == s[i + 1]) { i += 2; } else { break; } } if (i < j) { cout << "Alice\n"; } else { cout << "Draw\n"; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { Solve(); } return 0; }
Educational Codeforces Round 135 (Rated for Div. 2)(A-D)
最新推荐文章于 2024-06-15 16:46:40 发布