第十三届蓝桥杯 C/C++ 大学B组 题解
A
进制计算简单模拟
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
const int mod = 1e9 + 7;
signed main() {
int a[] = {2, 0, 2, 2};
int sum = 0;
for (int i = 0; i < 4; i++) {
sum = sum * 9 + a[i];
}
cout << sum << endl;
return 0;
}
// 答案1478
B
遍历2022的每一天,转成字符串拼接,然后判断
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
const int mod = 1e9 + 7;
bool check(string s) {
for (int i = 1; i < s.size() - 1; i++) {
if (s[i] - s[i - 1] == 1 && s[i + 1] - s[i - 1] == 1) return true;
}
return false;
}
signed main() {
int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int ans = 0;
for (int i = 1; i <= 12; i++) {
for (int j = 1; j <= month[i]; j++) {
string y = "2022";
if (i < 10)
y = y + "0" + to_string(i);
else {
y = y + to_string(i);
}
if (j < 10)
y = y + "0" + to_string(j);
else {
y = y + to_string(j);
}
if (check(y)) ans += 1;
// cout << y << endl;
}
}
cout << ans << endl;
return 0;
}
C
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
const int mod = 1e9 + 7;
signed main() {
ll a, b, n;
cin >> a >> b >> n;
ll week = n / (a * 5 + b * 2);
ll dy = n % (a * 5 + b * 2);
ll ans = week * 7;
if (dy <= 5 * a) {
ans = ans + (dy + a - 1) / (a);
} else {
ans += 5;
dy -= 5 * a;
ans = ans + (dy + b - 1) / b;
}
cout << ans << endl;
return 0;
}
D
找规律
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
const int mod = 1e9 + 7;
// 暴力找出规律
vector<int> solve(int n) {
// int n;
// cin >> n;
vector<int> a(n + 1, 0), ans(n + 1, 0);
int op = 1;
while (op <= 100) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
a[j] += 1;
}
// cout << "第" << op << "天傍晚"
// << "\n";
for (int j = 1; j <= n; j++) {
// cout << a[j] << " ";
ans[j] = max(ans[j], a[j]);
}
// cout << "\n";
a[i] = 0;
op += 1;
}
for (int i = n - 1; i > 1; i--) {
for (int j = 1; j <= n; j++) {
a[j] += 1;
}
// cout << "第" << op << "天傍晚"
// << "\n";
for (int j = 1; j <= n; j++) {
// cout << a[j] << " ";
ans[j] = max(ans[j], a[j]);
}
a[i] = 0;
// cout << "\n";
op += 1;
}
}
// cout << n << endl;
// for (int i = 1; i <= n; i++) {
// cout << ans[i] << " ";
// }
return ans;
}
void work() {
int n;
cin >> n;
if (n == 1) {
cout << 1 << endl;
return;
}
vector<int> vec(n + 1, 0);
int num = (n - 1) * 2;
for (int i = 1; i <= n / 2; i++) {
vec[i] = vec[n - i + 1] = num;
num -= 2;
}
if (n % 2 == 1) {
vec[n / 2 + 1] = n - 1;
}
for (int i = 1; i <= n; i++) {
cout << vec[i] << " ";
}
cout << endl;
}
signed main() {
// for (int i = 1; i <= 100; i++) {
// solve(i);
// cout << endl;
// }
work();
return 0;
}
/*
0 0 0 第一天早上
1 1 1 第一天晚上
0 1 1 第二天早上
1 2 2 第二天晚上
1 0 2 第三天早上
2 1 3 第三天晚上
2 1 0 第四天早上
3 2 1 第四天晚上
3 0 1 第五天早上
4 1 2 第五天晚上
*/
E
主要就是看懂题意和取模的问题。
321
对应八进制、十进制、二进制
计算过程为: 3 ∗ 10 ∗ 2 + 2 ∗ 2 + 1 = 65 3*10*2+2*2+1 = 65 3∗10∗2+2∗2+1=65
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
const int N = 1e5 + 7;
const int mod = 1e9 + 7;
int X, n, m;
int a[N], b[N];
int get_bit(int a, int b, int c) {
return (a > b ? a : b) > c ? (a > b ? a : b) : c;
}
signed main() {
cin >> X;
cin >> n;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for (int i = n; i >= 1; i--) cin >> a[i];
cin >> m;
for (int i = m; i >= 1; i--) cin >> b[i];
ll ans = 0;
for (int i = n; i > 1; i--) {
ans = ((ans + a[i] - b[i]) * get_bit(a[i - 1] + 1, b[i - 1] + 1, 2)) % mod;
}
ans += a[1] - b[1];
cout << ans << endl;
return 0;
}
/*
321 65
3*10*2+2*2+1 = 65
*/
F
通过枚举上下边界,和前缀和,就转成了一维数组求子段和小于等于k的问题文章来源:https://www.toymoban.com/news/detail-410566.html
经典双指针解决文章来源地址https://www.toymoban.com/news/detail-410566.html
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
const int mod = 1e9 + 7;
ll a[510][510];
signed main() {
ll n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
a[i][j] += a[i - 1][j];
}
}
ll ans = 0;
// 通过枚举上下边界,和前缀和,就转成了一维数组求子段和小于等于k的问题
// 经典双指针解决
for (int i = 1; i <= n; i++) { //枚举上边届
for (int j = i; j <= n; j++) { // 枚举下边界
int l = 1;
ll sum = 0;
for (int r = 1; r <= m; r++) {
sum += a[j][r] - a[i - 1][r];
while (sum > k) {
sum -= a[j][l] - a[i - 1][l];
l++;
}
ans += r - l + 1;
}
}
}
cout << ans << endl;
return 0;
}
G
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
const int N = 1e5 + 7;
const int mod = 1e9 + 7;
signed main() {
int n;
cin >> n;
vector<int> dp(n + 4, 0);
dp[1] = 1;
dp[2] = 2;
dp[3] = 5;
for (int i = 4; i <= n; i++) {
dp[i] = (dp[i - 1] * 2 % mod + dp[i - 3] % mod) % mod;
}
cout << dp[n] << endl;
return 0;
}
到了这里,关于第十三届蓝桥杯 C/C++ 大学B组 题解的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!