TOJ-1959. Oil Deposits

来源:互联网 发布:电视盒子看电影软件 编辑:程序博客网 时间:2024/05/16 07:34

//和以前做过的一道题有点像,想占座一样,找到能坐的就贴个标签

#include <cstdio>#include <cstring>using namespace std;char s[110][110];int m, n, cnt; void search(int x, int y){if (x >= 0 && y >= 0 && x < m && y < n && s[x][y] == '@'){s[x][y] = '0';search(x, y + 1); search(x + 1, y + 1);search(x + 1, y); search(x + 1, y - 1);search(x - 1, y); search(x - 1, y - 1);search(x, y - 1); search(x - 1, y + 1);}}int main(){while (scanf("%d%d", &m, &n) != EOF, m){for (int i = 0; i < m; i++)scanf("%s", &s[i]);cnt = 0;for (int i = 0; i < m; i++)for (int j = 0; j < n; j++){if (s[i][j] == '@')cnt++, search(i, j);}printf("%d\n", cnt);}return 0;}


0 0
原创粉丝点击