A30859.瓷砖 题解
2025-08-15 20:03:43
发布于:北京
2阅读
0回复
0点赞
解:
#include<iostream>
#include<queue>
using namespace std;
struct nodes{
int x,y;
} t;
int nexts[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int main(){
queue<nodes> q;
int n,m,i,j,js=1,zd=0;
int a[110][110];
cin>>m>>n;
string s;
for(i=1;i<=m;i++){
cin>>s;
for(j=0;j<n;j++){
if (s[j]=='#'){
a[i][j+1]=0;
}
else{
a[i][j+1]=1;
}
if (s[j]=='@'){
t.x=i;
t.y=j+1;
}
}
}
a[t.x][t.y]=0;
q.push(t);
while(!q.empty()){
for(int k=0;k<=3;k++){
t.x=q.front().x+nexts[k][0];
t.y=q.front().y+nexts[k][1];
if(a[t.x][t.y]==1){
q.push(t);
a[t.x][t.y]=0;
js++;
}
}
q.pop();
}
cout<<js;
return 0;
}
这里空空如也
有帮助,赞一个