santisify Site

Back

Atcoder beginner contest 373Blur image

A September#

September

题目描述#

1212 个字符串 S1,S2,S3,S12S_1, S_2, S_3, \cdots S_{12} 问有几个字符串满足 Si=i(1i12)S_{i} = i (1 \le i \le 12)

太简单不需要解释

参考代码#

#include<bits/stdc++.h>

#define int long long
#define endl '\n'
#define pii std::pair<int ,int>
#define fix(x) std::fixed << std::setprecision(x)
const int inf = 1e17 + 50, MAX_N = 1e5 + 50, mod = 1e9 + 7;

void solve() {
	int ct = 0;
	for(int i = 0; i < 12; i++) {
		std::string s;
		std::cin >> s;
		if (s.size() == i + 1) ct++;
	}
	std::cout << ct << endl;
}

signed main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr), std::cout.tie(nullptr);
	solve();
	return 0;
}
cpp

B 1D Keyboard#

1D Keyboard

题目描述#

给定长度为 2626 的字符串,并且保证字符串每个英文字母只出现一次,当前第 00 步时处于 AA 点, 问需要走多少步会使得字符串所走过的路径为 ABC.....XYZABC.....XYZ.简单点说就是从 AA 点走到 BB 点,再到 CC 点,以此类推,知道 ZZ 点,至少需要走多少步?

解题思路#

由于字符串中一个字母只会出现一次,我们就可以将每个字母的位置记录下来,然后再依次算出相邻两个点的距离,即可得出答案.

参考代码#

#include<bits/stdc++.h>

#define int long long
#define endl '\n'
#define pii std::pair<int ,int>
#define fix(x) std::fixed << std::setprecision(x)
const int inf = 1e17 + 50, MAX_N = 1e5 + 50, mod = 1e9 + 7;

void solve() {
	std::string s;
	std::cin >> s;

	std::map<char, int> mp;
	for(int i = 0; i < s.size(); i++) {
		mp[s[i]] = i;
	}
	int now = mp['A'];
	int w = 0;
	mp.erase('A');
	for(auto [c, pos] : mp) {
		w += abs(now - pos);
		now = pos;
	}

	std::cout << w << endl;
}

signed main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr), std::cout.tie(nullptr);
	solve();
	return 0;
}
cpp

C Max Ai+Bj#

Max Ai+Bj

题目描述#

给你两个整数序列 AABB ,每个长度为 NN 。请选择整数 i,ji, j (1i,jN)(1 \leq i, j \leq N) 使其长度最大化。 (1i,jN)(1 \leq i, j \leq N) 使 Ai+BjA _{i} + B_{j} 的值最大。输出最大值。

解题思路#

选择尽量大的 i,ji,j 使得 Ai+BjA_{i} + B_{j}最大,为了使得和最大,只需要分别选择两个数组的最大值,才能使得和最大。

参考代码#

#include<bits/stdc++.h>

#define int long long
#define endl '\n'
#define pii std::pair<int ,int>
#define fix(x) std::fixed << std::setprecision(x)
const int inf = 1e17 + 50, MAX_N = 1e5 + 50, mod = 1e9 + 7;

void solve() {
	int n;
	std::cin >> n;
	std::vector<int> a(n), b(n);

	for(int i = 0, x; i < n; i++) {
		std::cin >> a[i];
	}
	for(int i = 0, x; i < n; i++) {
		std::cin >> b[i];
	}
	std::sort(a.begin(), a.end());
	std::sort(b.begin(), b.end());
	std::cout << a[n - 1] + b[n - 1] << endl;
}

signed main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr), std::cout.tie(nullptr);
	solve();
	return 0;
}
cpp
Atcoder beginner contest 373
https://santisify.top/blog/old/abc373
Author santisify
Published at August 25, 2024
Comment seems to stuck. Try to refresh?✨