0
已解决
题目描述 Description
如下图所示,在10 * 10的二维数组中,有“ * ”围住了15个“0”。若“0”在 * 号所围成的闭合曲线中水平线和垂直线交点的上,则“0”被围住。
现在以“1”替换“ * ”,请你编程计算被“1”围住的0的个数。
输入描述 Input Description
输入一个由0、1组成的10*10的二维数组
输出描述 Output Description
输出被“1”围住的“0”的个数
样例输入 Sample Input
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 0 1 1 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
样例输出 Sample Output
15
————————————————————————————————————————————————————————
看上去这道题很简单
但是怎么写能?
错误代码大佬找错!
#include<bits/stdc++.h>
using namespace std;
int sum_1;
int t,w;
int mapp[12][12];
int f[145][2];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int main(){
for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
scanf("%d",&mapp[i][j]);
if(mapp[i][j]==1) sum_1++;
}
}
t=1,w=1;
mapp[0][0]==1;
f[t][0]=f[t][1]=0;
while(t<=w){
for(int i=0;i<4;i++){
int xx=f[t][0]+dx[i],yy=f[t][1]+dy[i];
if(xx>=0&&xx<=11&&yy>=0&&yy<=11&&!mapp[xx][yy]){
mapp[xx][yy]=1;
f[++w][0]=xx;
f[w][1]==yy;
}
}
t++;
}
printf("%d\n",144-w-sum_1);
return 0;
}