赞
踩
Dashboard - Codeforces Round 863 (Div. 3) - Codeforces
这场比赛我打的不太好,所以我准备写个题解总结一下。
A 题,这个题说是找出插入数字的地方使得这个 n + 1 位数字最大,我们首先会想到的就是找出比这个数比这个数小的第一个数然后在它的前面插入就行。记得插完之后记录一下,防止重复输出。
代码:
- #include <bits/stdc++.h>
- #include <iomanip>
- #define int long long
- using namespace std;
- void solve() {
- int n, k;
- cin >> n >> k;
- string s;
- cin >> s;
- bool flag = false;
- for (int i = 0; i < n; i ++) {
- if (!flag && (s[i] - '0') < k) {cout << k << s[i]; flag = true;}
- else cout << s[i];
- }
- if (!flag) cout << k;
- cout << "\n";
- }
- signed main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int t;
- cin >> t;
- while (t --) {
- solve();
- }
- return 0;
- }
B
找离墙最近的就行
代码
- #include <bits/stdc++.h>
- main()
- {
- int t; std::cin >> t;
- while (t--)
- {
- int n, x1, y1, x2, y2;
- std::cin >> n >> x1 >> y1 >> x2 >> y2;
- int a = std::min({x1, y1, n + 1 - x1, n + 1 - y1});
- int b = std::min({x2, y2, n + 1 - x2, n + 1 - y2});
- std::cout << std::abs(a - b) << "\n";
- }
- return 0;
- }
C
先放两边,再放中间
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- signed main() {
- int t;
- cin >> t;
- while (t--) {
- int n;
- cin >> n;
- vector<int> b(n - 1), a(n, -1);
- for (int i = 0; i < n - 1; i ++) cin >> b[i];
- for (int i = 0; i < n; i ++) {
- if (!i) {
- a[i] = b[i];
- }
- else if (i == n - 1) {
- a[i] = b[i - 1];
- }
- else a[i] = min(b[i], b[i - 1]);
- }
- for (int i = 0; i < n; i ++) cout << a[i] << " \n"[i == n - 1];
- }
- return 0;
- }
D
代码
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
-
- /*
- 长宽分别是 f[n], f[n + 1]
- */
-
- constexpr int N = 50;
- int f[N];
-
- bool dfs(int n, int x, int y)
- {
- if (!n) return true;
- if (y > f[n]) return dfs(n - 1, f[n + 1] - y + 1, x);
- if (y <= f[n - 1]) return dfs(n - 1, y, x);
- return false;
- }
-
- void solve()
- {
- int n, x, y; cin >> n >> x >> y;
- cout << (dfs(n, x, y) ? "YES" : "NO") << "\n";
- }
- signed main()
- {
- f[0] = f[1] = 1;
- for (int i = 2; i <= 45; i ++)
- f[i] = f[i - 1] + f[i - 2];
- int t; cin >> t;
- while (t--)
- {
- solve();
- }
- return 0;
- }
E
代码
这道题可以看成一个九进制的数
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
-
- void solve()
- {
- int k; cin >> k;
- string ans = "";
- while (k)
- {
- int a = k % 9;
- if (a < 4) ans += a + '0';
- else ans += a + 1 + '0';
- k /= 9;
- }
- reverse(ans.begin(), ans.end());
- cout << ans << "\n";
- }
-
- signed main()
- {
- int t; cin >> t;
- while (t --)
- {
- solve();
- }
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。