题目:
问题 F: DS图—图非0面积
时间限制: 1 Sec 内存限制: 128 MB
提交: 267 解决: 195
[提交][状态][讨论版]
题目描述
编程计算由"1"围成的下列图形的面积。面积计算方法是统计"1"所围成的闭合曲线中"0"点的数目。如图所示,在10*10的二维数组中,"1"围住了15个点,因此面积为15。
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/bce5e09e716ce2a38768e529f7b95847.jpeg)
输入
测试次数t
每组测试数据格式为:
数组大小m,n
一个由0和1组成的m*n的二维数组
输出
对每个二维数组,输出符号"1"围住的"0"的个数,即围成的面积。假设一定有1组成的闭合曲线,但不唯一。
样例输入
2
10 10
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
5 8
0 1 1 0 0 1 1 0
1 0 1 0 1 0 0 1
0 1 0 1 0 0 1 0
0 1 0 0 1 1 1 0
0 0 0 0 0 0 0 0
样例输出
15
5
代码块:
#include <iostream>
#include <queue>
using namespace std;
class Matrix
{
private:
int m;
int n;
int **matrix;
public:
Matrix();
~Matrix();
void CreateMatrix();
void BFS();
};
Matrix::Matrix()
{
cin>>m>>n;
matrix = new int*[m+2];
for(int i=0; i<m+2; i++)
matrix[i] = new int[n+2];
}
Matrix::~Matrix()
{
for(int i=0; i<m+2; i++)
delete []matrix[i];
delete []matrix;
}
void Matrix::CreateMatrix()
{
int i, j;
for(i=0; i<m+2; i++)
for(j=0; j<n+2; j++)
matrix[i][j] = 0;
for(i=1; i<=m; i++)
for(j=1; j<=n; j++)
cin>>matrix[i][j];
}
void Matrix::BFS()
{
}