题解:AT_xmascon19_f Stamps 1
Algorithm_Ghost · · 题解
1.思路
这是一个经典的位掩码枚举问题。由于印章的大小固定了,
长为
2.方法
所以我们只要分
我们只需要遍历每一个白色格子,然后判断在哪个象限就行了。
3.代码实现
#include<bits/stdc++.h>
using namespace std;
int main() {
int H,W, ans = 0;
cin >>H>>W;
vector<string> s(H);
for (int i = 0; i < H; ++i) cin >> s[i];
int h = H / 2;
int w = W / 2;
bool need[4] = {false, false, false, false};
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
if (S[i][j] == '.') {
if (i < h && j < w) need[0] = true;
else if (i < h && j >= w) need[1] = true;
else if (i >= h && j < w) need[2] = true;
else if (i >= h && j >= w) need[3] = true;
}
}
}
for (int k = 0; k < 4; ++k)if (need[k] )ans++;
cout << ans <<endl;
}
这就是所有代码了。
各位 dalao 请点赞,别逼我求你,QAQ~~