本文主要是介绍Educational Codeforces Round 157 (Rated for Div. 2),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Educational Codeforces Round 157 (Rated for Div. 2)
A
模拟
#include <bits/stdc++.h>using namespace std;const int N = 3e5 + 10;void solve()
{int x , y , k;cin >> x >> y >> k;if(y <= x){cout << x << endl;}else if(x + k >= y){cout << y << endl;}else if(x + k < y){cout << y + (y - x - k) << endl;}
}int main()
{int T = 1;cin >> T;while(T--){solve();}return 0;
}
B
贪心排序
#include <bits/stdc++.h>using namespace std;const int N = 3e5 + 10;
int a[N];void solve()
{int n;cin >> n;for (int i = 1; i <= 2 * n; i++){cin >> a[i];}sort(a + 1, a + 1 + n + n);int ans = 0;for (int i = 2; i <= n; i++){ans += (a[i] - a[i - 1]) + (a[i + n] - a[i + n - 1]);}cout << ans << endl;for (int i = 1; i <= n; i++){cout << a[i] << " " << a[i + n] << endl;}
}int main()
{int T = 1;cin >> T;while (T--){solve();}return 0;
}
C
枚举所有可能的长度
#include <bits/stdc++.h>using i64 = long long;int main() {std::ios::sync_with_stdio(false);std::cin.tie(nullptr);int n;std::cin >> n;std::array<std::vector<std::string>, 6> f;for (int i = 0; i < n; i++) {std::string s;std::cin >> s;f[s.size()].push_back(s);}i64 ans = 0;for (int x = 1; x <= 5; x++) {for (int y = 1; y <= 5; y++) {if ((x + y) % 2 == 0) {std::array<int, 100> cnt{};int h = (x + y) / 2;for (auto a : f[x]) {int s = 50;for (int i = 0; i < x; i++) {if (i < h) {s += a[i] - '0';} else {s -= a[i] - '0';}}cnt[s] += 1;}for (auto a : f[y]) {int s = 50;for (int i = 0; i < y; i++) {if (x + i >= h) {s += a[i] - '0';} else {s -= a[i] - '0';}}ans += cnt[s];}}}}std::cout << ans << "\n";return 0;
}
这篇关于Educational Codeforces Round 157 (Rated for Div. 2)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!