提交时间:2024-01-21 20:41:21

运行 ID: 121484

#include<iostream> #include<queue> using namespace std; int dx[4]={1,-1,0,0}; int dy[4]={0,0,-1,1}; bool a[11][11]; struct Node{ int x; int y; }; queue<Node> q; void bfs(int tx,int ty){ Node start={tx,ty}; q.push(start); while(q.empty()==false){ Node front=q.front(); a[front.x][front.y]=1; q.pop(); for(int i=0;i<4;i++){ int xx=front.x+dx[i]; int yy=front.y+dy[i]; if(((xx>0 && xx<=10) && (yy>0 && yy<=10)) && a[xx][yy]==0){ Node node={xx,yy}; q.push(node); } } } } int main(){ int s=0; for(int i=1;i<=10;i++){ for(int j=1;j<=10;j++){ cin>>a[i][j]; } } for(int i=1;i<=10;i++){ for(int j=1;j<=10;j++){ if(i==1 || j==1 || i==10 || j==10){ bfs(i,j); } } } for(int i=1;i<=10;i++){ for(int j=1;j<=10;j++){ if(a[i][j]==0){ s++; } } } cout<<s<<endl; return 0; }