其实思路很简单的。。一行一行的扫,在两个/ \之间的点就是黑色要求的
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
using namespace std;
const int INF = ~0U >> 1;
const int maxn = 100+5;
int m, n;
char str[maxn][maxn];
int main()
{
while(scanf("%d%d", &m, &n) != EOF) {
int ans = 0;
double cnt = 0;
for(int i = 0; i < m; ++i) {
scanf("%s", str[i]);
for(int j = 0; j < n; ++j)
if(str[i][j] == '/' || str[i][j] == '\\') cnt += 0.5;
}
for(int i = 0; i < m; ++i) {
bool ok = false;
for(int j = 0; j < n; ++j) {
if(str[i][j] == '/' || str[i][j] == '\\') ok = !ok;
if(ok && str[i][j] == '.') ++ans;
}
}
cout << (double)ans + cnt << endl;
}
return 0;
}
本文介绍了一种简单有效的网格黑白棋计数方法。通过扫描输入的网格,并利用特定符号来区分黑白棋子的位置,该算法能准确计算出网格中黑色棋子的数量,并通过巧妙的逻辑处理实现对半格棋子的计数。
2964

被折叠的 条评论
为什么被折叠?



