A - Double Click (签到题)
题目给出的序列已经是有序的了,直接计算就好。
参考代码:
#include <bits/stdc++.h>
#define i64 long long
inline int read() {
bool sym = false; int res = 0; char ch = getchar();
while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();
while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
return sym ? -res : res;
}
int main() {
int N = read(), D = read();
std::vector<int> A(N);
for (int i = 0; i < N; i++) {
A[i] = read();
}
for (int i = 0; i < N - 1; i++) {
if (A[i + 1] - A[i] <= D) {
printf("%d\n", A[i + 1]);
return 0;
}
}
printf("-1\n");
return 0;
}
B - chess960 (签到题)
记录一下位置。
参考代码:
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string s;
std::cin >> s;
int pos1 = s.find('B');
int pos2 = s.find('B', pos1 + 1);
int pos3 = s.find('K');
int pos4 = s.find('R');
int pos5 = s.find('R', pos4 + 1);
if ((pos1 % 2 != pos2 % 2) && pos3 > pos4 && pos3 < pos5) {
std::cout << "Yes\n";
} else {
std::cout << "No\n";
}
return 0;
}
C - PC on the Table (签到题)
签到题 (模拟)。
参考代码:
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int H, W;
std::cin >> H >> W;
for (int i = 0; i < H; i++) {
std::string s;
std::cin >> s;
for (int j = 0; j < W - 1; j++) {
if (s[j] == 'T' && s[j + 1] == 'T') {
s[j] = 'P', s[j + 1] = 'C';
}
}
std::cout << s << "\n";
}
return 0;
}
D - Count Subtractions (思维)
注意到如果 A > B 的话,操作一都是重复的 A 减 B,那么 A 就会变成 A 模 B 的余数。B > A 的情况同理。因此我们直接模拟一遍这个过程即可。
参考代码:
#include <bits/stdc++.h>
#define i64 long long
inline i64 read() {
bool sym = false; i64 res = 0; char ch = getchar();
while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();
while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
return sym ? -res : res;
}
i64 work(i64 &a, i64 &b, bool &flag) {
if (a % b == 0) {
flag = true;
return a / b - 1;
}
i64 res = a / b;
a %= b;
return res;
}
int main() {
i64 a = read(), b = read(), ans = 0;
while (a != b) {
bool flag = false;
if (a > b) ans += work(a, b, flag);
else ans += work(b, a, flag);
if (flag) break;
}
printf("%lld\n", ans);
return 0;
}
E - Kth Takoyaki Set (思维,STL::set)
开一个 set,循环 k 次,每一次取出当前集合中的最小元素,然后再选一个最便宜的章鱼烧加上x,添加进集合就行了。循环 k 次之后,集合首元素就是答案。
那为什么这样是对的呢?首先这样取出来的一定是最小值,而且我们每次取的最小值会加上一个最便宜的章鱼烧的价格然后再添加到集合中,所以我们求出的最小值是不会重复的,故答案正确.
参考代码:
#include <bits/stdc++.h>
#define i64 long long
inline int read() {
bool sym = false; int res = 0; char ch = getchar();
while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();
while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
return sym ? -res : res;
}
int main() {
int N = read(), K = read();
std::vector<int> A(N);
for (int i = 0; i < N; i++) {
A[i] = read();
}
std::set<i64> S{0};
for (int i = 0; i < K; i++) {
i64 x = *S.begin();
S.erase(x);
for (int j = 0; j < N; j++) {
S.insert(x + A[j]);
}
}
std::cout << *S.begin() << "\n";
return 0;
}