111
Posted astonc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了111相关的知识,希望对你有一定的参考价值。
#include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; const int MAX = 100; int N, M, cnt; char maze[MAX][MAX]; bool vis[MAX][MAX]; int sx, sy; int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1}; int bfs () { //cout<<"1"<<endl; queue<pair<int, int> > q; int cnt = 0; q.push(make_pair(sx, sy)); vis[sx][sy] = true; while (!q.empty()) { int x = q.front().first; int y = q.front().second; q.pop() ; for (int i = 0; i < 4; i++) { int nx = x + dir[i][0]; int ny = y + dir[i][1]; if(nx >= 0 && nx < N && ny >= 0 && ny < M && maze[nx][ny] == ‘.‘ && vis[nx][ny] == false) { vis[nx][ny] = true; q.push(make_pair(nx, ny)); } } cnt++; } return cnt; } int main () { while (cin >> N >> M && N != 0) { //while (~scanf("%d%d", &N, &M) && N != 0) { //getchar(); swap(N,M); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { //scanf("%c", &maze[i][j]); cin >> maze[i][j]; if (maze[i][j] == ‘@‘) { sx = i; sy = j; } } //getchar(); } memset (vis, false, sizeof(vis)); int ans = bfs(); printf("%d ", ans); } }
以上是关于111的主要内容,如果未能解决你的问题,请参考以下文章