AcWing 第143场周赛

A. 时间

思路:

  • 基础语法

时间复杂度:\(O(1)\)

1
2
3
4
5
6
7
8
9
10
11
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);

int n;
std::cin >> n;

std::cout << (n % 12 ? n % 12 : 12) << "\n";

return 0;
}

B. 数对推理

思路:

  • 讲真的题目感觉都没说清楚,读起来莫名其妙的

时间复杂度:\(O()\)

C. 铺瓷砖

思路:

  • 设向量搜索即可,可以发现在竖着的方向上一直都有两个方块,所以我们可以设向量来搜索即可

时间复杂度:\(O(n)\)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);

std::vector<std::string> g(2);
for (int i = 0; i < 2; i++) {
std::cin >> g[i];
g[i] = '1' + g[i] + '1';
}

int n = g[0].size() - 2;

int ans = 0;
std::array<int, 4> dy {-1, -1, 1, 1}, dx {1, 0, 1, 0};
for (int i = 1; i <= n; i++) {
if (g[1][i] == '0' && g[0][i] == '0') {
for (int j = 0; j < 4; j++) {
int x = dx[j], y = dy[j] + i;
if (g[x][y] == '0') {
g[x][y] = g[0][i] = g[1][i] = '1';
ans++;
break;
}
}
}
}
std::cout << ans << "\n";

return 0;
}