# SSL-ZYC 2324 cell problem

Main idea:
A rectangular array consists of the numbers 0 to 9. The numbers 1 to 9 represent cells. The definition of cells is whether the number of cells is the same cell along the top and bottom of the cell number or the cell number. Find the number of cells in a given rectangular array.

For example: There are 4 cells in all.

Ideas:
This is a problem of BFS. Search a[n][m] from a, find a cell, then clear the cell and the cell next to it, and count.

That is to say, BFS is carried out once every cell is found, and the next cell is searched after clearing the adjacent cells.

(warm tip: the numbers 1, 2, 3, 4, 5, 6, 7, 8 and 9 are actually the same. They are all cells and do not need to be treated separately.)

code:

```#include <iostream>
#include <cstdio>
using namespace std;
bool a;
int n,m,father,state,sum;
int dx={0,0,0,1,-1};
int dy={0,-1,1,0,0};

void bfs(int x,int y)
{
tail=1;
father=0;
a[x][y]=0;
state=x;
state=y;  //initialization
do
{
for (i=1;i<=4;i++)
{
if (qx>0&&qx<=n&&qy>0&&qy<=m&&a[qx][qy])  //If it's not out of bounds and it's a cell
{
tail++;
state[tail]=qx;
state[tail]=qy;
a[qx][qy]=0;
}
}
}
}
int main()
{
int i,j;
scanf("%d%d\n",&n,&m);
for (i=1;i<=n;i++)
{
for (j=1;j<=m;j++)
{
}
}
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)  //Cell by cell
{
if (a[i][j]==1)  //If this is a cell
{
bfs(i,j);  //Look for the cell next to it
sum++;  //count
}
}
printf("%d",sum);
return 0;
}```

(this problem is very similar to finding oil, basically the same way.)

Posted by dt_gry on Tue, 05 May 2020 17:54:28 -0700