字母数
贪心,保证每一位都是A就可以了。
参考代码:
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int res = 0;
for (int i = 1; ; i++) {
res += 10 * (int)std::pow(16, i - 1);
if (res > 2022) {
std::cout << res << "\n";
break;
}
}
return 0;
}
特殊日期
枚举。
参考代码:
#include <bits/stdc++.h>
bool isrunnian(int year) {
if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {
return true;
}
return false;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int ans = 0;
for (int year = 1900; year <= 9999; year++) {
for (int month = 1; month <= 12; month++) {
for (int day = 1; day <= ((isrunnian(year) && month == 2) ? days[month] + 1 : days[month]); day++) {
std::string s = std::to_string(year * 10000 + month * 100 + day * 1);
int x = 0, y = 0;
for (int i = 0; i < 4; i++) {
x += (s[i] - '0');
}
for (int i = 4; i < 8; i++) {
y += (s[i] - '0');
}
if (x == y) {
ans += 1;
}
}
}
}
std::cout << ans << "\n";
return 0;
}
大乘积
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int nums[40];
for (int i = 1; i <= 30; i++) {
std::cin >> nums[i];
}
int ans = 0;
for (int i = 1; i < 30; i++) {
for (int j = i + 1; j <= 30; j++) {
ans += (nums[i] * nums[j] >= 2022);
}
}
std::cout << ans;
return 0;
}
滑行
记忆化搜索。
#include <bits/stdc++.h>
#define i64 long long
const int N = 110;
int n, m;
int a[N][N], f[N][N];
int dir[5] = {0, 1, 0, -1, 0};
int dfs(int x, int y) {
if (f[x][y] != -1) {
return f[x][y];
}
f[x][y] = 1;
for (int k = 0; k < 4; k ++) {
int dx = x + dir[k], dy = y + dir[k + 1];
if (dx > 0 && dx <= n && dy > 0 && dy <= m && a[x][y] > a[dx][dy]) {
f[x][y] = std::max(f[x][y], dfs(dx, dy) + 1);
}
}
return f[x][y];
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
std::cin >> a[i][j];
}
}
std::memset(f, -1, sizeof f);
int ans = -10000;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
ans = std::max(ans, dfs(i, j));
}
}
std::cout << ans << "\n";
return 0;
}
星期几
#include <bits/stdc++.h>
#define i64 long long
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 n, m;
std::cin >> n >> m;
std::cout << ((n + m) % 7 == 0 ? 7 : (n + m) % 7) << "\n";
return 0;
}
清理水域
#include <bits/stdc++.h>
#define i64 long long
bool vis[110][110];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
int ans = 0;
int t;
std::cin >> t;
while (t--) {
int r1, c1, r2, c2;
std::cin >> r1 >> c1 >> r2 >> c2;
for (int i = r1; i <= r2; i++) {
for (int j = c1; j <= c2; j++) {
if (!vis[i][j]) {
ans++;
vis[i][j] = true;
}
}
}
}
std::cout << n * m - ans << "\n";
return 0;
}
附近最小
ST表板子题,不过需要特判越界情况。
#include <bits/stdc++.h>
#define i64 long long
const int N = 1e6 + 10;
int a[N], n;
i64 F[N][20];
void Min_ST() {
for (int i = 1; i <= n; i++) {
F[i][0] = a[i];
}
int k = std::log(n) / std::log(2);
for (int j = 1; j <= k; j++) {
for (int i = 1; i <= n - (1 << j) + 1; i++) {
F[i][j] = std::min(F[i][j - 1], F[i + (1 << (j - 1))][j - 1]);
}
}
}
int Range_Min(int l, int r) {
int k = std::log2(r - l + 1);
return std::min(F[l][k], F[r - (1 << k) + 1][k]);
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> n;
for (int i = 1; i <= n; i++) {
std::cin >> a[i];
}
Min_ST();
int k;
std::cin >> k;
for (int i = 1; i <= n; i++) {
if (i - k < 1) {
std::cout << Range_Min(1, i + k) << " ";
} else if (i + k > n) {
std::cout << Range_Min(i - k, n) << " ";
} else if (i - k < 1 && i + k > n) {
std::cout << Range_Min(1, n) << " ";
} else {
std::cout << Range_Min(i - k, i + k) << " ";
}
}
return 0;
}
判断蓝桥
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string s;
std::cin >> s;
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
if (s == "lanqiao") {
std::cout << "yes";
} else {
std::cout << "no";
}
return 0;
}
列名
进制问题。
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::vector<int> nums;
int n = 2022;
while (n) {
nums.emplace_back(n % 26);
n /= 26;
}
std::reverse(nums.begin(), nums.end());
for (auto i : nums) {
std::cout << (char)('A' + i - 1);
}
return 0;
}
信号覆盖
#include <bits/stdc++.h>
#define i64 long long
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int W, H, n, R;
std::cin >> W >> H >> n >> R;
std::vector<int> X(n + 1), Y(n + 1);
for (int i = 1; i <= n; i++) {
std::cin >> X[i] >> Y[i];
}
int ans = 0;
for (int i = 0; i <= W; i++) {
for (int j = 0; j <= H; j++) {
for (int k = 1; k <= n; k++) {
if ((i - X[k]) * (i - X[k]) + (j - Y[k]) * (j - Y[k]) <= R * R) {
ans++;
break;
}
}
}
}
std::cout << ans << "\n";
return 0;
}