1 solutions
-
0
#include<bits/stdc++.h> using namespace std; char mapp[55][55]; int w,h,ans,x,y; int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0}; struct wz{ int a,b; }; void dfs(int x,int y){ queue<wz>q; mapp[x][y]='#'; q.push({x,y}); while(q.size()>0){ wz xy=q.front(); q.pop(); for(int i=0;i<4;i++){ int x1=xy.a+dx[i],y1=xy.b+dy[i]; if(mapp[x1][y1]'.'&&x1>=1&&x1<=w&&y1>=1&&y1<=h){ q.push({x1,y1}); ans++; mapp[x1][y1]='#'; } } } } int main(){ cin>>h>>w; for(int i=1;i<=w;i++) for(int j=1;j<=h;j++){ cin>>mapp[i][j]; if(mapp[i][j]'@'){ x=i;y=j; } } ans=1; dfs(x,y); cout<<ans; return 0; }
- 1
Information
- ID
- 453
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- (None)
- # Submissions
- 20
- Accepted
- 10
- Uploaded By