4 solutions
-
0
#include<iostream> #include<queue> using namespace std; #define N 25 struct point{ int x; int y; }; queue<point> q; char a[N][N];//存地图 bool v[N][N]; int dx[4]={0,1,0,-1}; int dy[4]={1,0,-1,0}; int w,h,cnt; point start; int main() { //w列 h行 格子为h*w规格棋盘 cin>>w>>h; for(int i=0;i<h;i++) for(int j=0;j<w;j++){ cin>>a[i][j]; if(a[i][j]=='@'){ start.x=i; start.y=j; } } q.push(start); v[start.x][start.y]=true; while(!q.empty()){ point header=q.front(); for(int i=0;i<4;i++){ point temper=header; temper.x+=dx[i]; temper.y+=dy[i]; if(a[temper.x][temper.y]=='.'&&!v[temper.x][temper.y])q.push(temper); v[temper.x][temper.y]=true; } q.pop(); cnt++; } cout<<cnt<<endl; return 0; }
Information
- ID
- 1233
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 4
- Tags
- # Submissions
- 175
- Accepted
- 80
- Uploaded By