A.小红的数位删除
思路:
这题简单输出即可
Code:
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.size() - 3; i++) { cout << s[i]; } return 0; }
B.小红的小红矩阵构造
思路:
所有元素之和恰好等于x,且每行、每列的异或和全部相等使用set或者map等等都可以储存异或值,按题意来就行
Code:
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 5; int a[N][N], sum, tmp, n, m, x; set<int> st; int main() { cin >> n >> m >> x; for (int i = 1; i <= n; i++) { tmp = 0; for (int j = 1; j <= m; j++) { cin >> a[i][j]; sum += a[i][j]; tmp ^= a[i][j]; } st.insert(tmp); } for (int j = 1; j <= m; j++) { tmp = 0; for (int i = 1; i <= n; i++) { tmp ^= a[i][j]; } st.insert(tmp); } if (sum == x && st.size() == 1) cout << "accepted\n"; else cout << "wrong answer\n"; return 0; }
C.小红的白色字符串
思路:
1-开头第一个大写,其余小写(len=1也算)
2-所有都是小写
所以从前往后判定即可
Code:
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int cnt = 0; for (int i = 1; i < s.size(); i++) { if (s[i] >= 'A' && s[i] <= 'Z' && s[i - 1] != ' ') { cnt++; s[i] = ' '; } } cout << cnt; return 0; }
D.小红走矩阵
思路:
一个模板题bfs,能不能到达终点,能就输出最短的长度,不能输出-1
Code:
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; char a[N][N]; bool vis[N][N]; int n, m; int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; bool isVaild(int x, int y) { return !vis[x][y] && x >= 1 && x <= n && y >= 1 && y <= m; } void bfs() { queue<array<int, 3>> q; q.push({1, 1, 0}); vis[1][1] = 1; while (!q.empty()) { auto [x, y, cnt] = q.front(); q.pop(); if (x == n && y == m) { cout << cnt; return ; } for (int i = 0; i < 4; i++) { int dx = x + dir[i][0]; int dy = y + dir[i][1]; if (isVaild(dx, dy) && a[x][y] != a[dx][dy]) { vis[dx][dy] = 1; q.push({dx, dy, cnt + 1}); } } } cout << -1; } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; } } bfs(); return 0; }
E.小红的小红走矩阵
思路:
构造题 由于合法解 有个弯走就符合题意了
Code:
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; char mp[N][N]; int main() { int n, m; cin >> n >> m; mp[1][1] = mp[1][2] = 'a'; mp[2][1] = mp[3][1] = 'b'; mp[2][2] = mp[2][3] = mp[3][2] = 'c'; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (mp[i][j] == '\0') { if ((i + j) % 2 != 0) { mp[i][j] = 'a'; } else { mp[i][j] = 'b'; } } cout << mp[i][j]; } cout << "\n"; } return 0; }
标签:周赛,Code,int,小红,36,牛客,mp,using,include From: https://www.cnblogs.com/youhualiuh/p/18065029