#include<bits/stdc++.h> usingnamespace std; #define int long long signedmain() { int a, b; cin >> a >> b; a += b; a %= 12; if (a == 0) { cout << 12; } else { cout << a; } return0; }
B.Most Minority
题目描述
1,2,…,N 人(其中 N 为奇数)进行了 M 次投票,每个人都选择了 "0 "或 “1”。
每个人在每一轮投票中的票数是由长度为 M 的 N 字符串 S1,S2,…,SN 给出的,字符串由 "0 "和 "1 "组成,其中 Si 的 j -th字符代表 i 人在 j -th投票中的投票内容。
#include<bits/stdc++.h> usingnamespace std; #define int long long signedmain() { int n, q; cin >> n >> q; vector<int> a(n + 1), b(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { cin >> b[i]; } int ans = 0; for (int i = 1; i <= n; i++) { ans += min(a[i], b[i]); } for (int i = 0; i < q; i++) { char c; int x, y; cin >> c >> x >> y; if (c == 'A') { ans -= min(a[x], b[x]); a[x] = y; ans += min(a[x], b[x]); } else { ans -= min(a[x], b[x]); b[x] = y; ans += min(a[x], b[x]); } cout << ans << '\n'; } return0; }
D.Toggle Maze
题目描述
有一个网格,网格中有 H 行和 W 列。让 (i,j) 表示位于从上往下第 i 行和从左往上第 j 列的单元格。每个单元格的状态用字符 Ai,j 表示,其含义如下:
#include<bits/stdc++.h> usingnamespace std; #define int long long int n, m; vector<vector<char>> a; int sx, sy; int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; signedmain() { cin >> n >> m; a.resize(n, vector<char>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; if (a[i][j] == 'S') { sx = i; sy = j; } } } vector<vector<vector<int>>> dist(n, vector<vector<int>>(m, vector<int>(2, -1))); queue<vector<int>> q; dist[sx][sy][0] = 0; q.push({sx, sy, 0}); while (!q.empty()) { vector<int> tp = q.front(); q.pop(); int x = tp[0], y = tp[1], z = tp[2]; for (int i = 0; i < 4; i++) { int dx = x + dir[i][0]; int dy = y + dir[i][1]; if (dx < 0 || dx >= n || dy < 0 || dy >= m) { continue; } if (a[dx][dy] == '#') { continue; } if (a[dx][dy] == 'x') { if (z % 2 == 0) { continue; } } if (a[dx][dy] == 'o') { if (z % 2 == 1) { continue; } } int tpz = z; if (a[dx][dy] == '?') { tpz = (z + 1) % 2; } if (dist[dx][dy][tpz] == -1) { dist[dx][dy][tpz] = dist[x][y][z] + 1; q.push({dx, dy, tpz}); if (a[dx][dy] == 'G') { cout << dist[x][y][z] + 1; return0; } } } } cout << -1; return0; }