A September
题目描述
有
问有几个字符串满足
太简单不需要解释
参考代码
#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;}B 1D Keyboard
题目描述
给定长度为
解题思路
由于字符串中一个字母只会出现一次,我们就可以将每个字母的位置记录下来,然后再依次算出相邻两个点的距离,即可得出答案.
参考代码
#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;}C Max Ai+Bj
题目描述
给你两个整数序列
解题思路
选择尽量大的
使得 最大,为了使得和最大,只需要分别选择两个数组的最大值,才能使得和最大。
参考代码
#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;}