题目:You have taken the graduation picture of graduates. The picture could be regarded as a matrix A of n×n, each element in A is 0 or 1, representing a blank background or a student, respectively.
However, teachers are too busy to take photos with students and only took a group photo themselves. The photo could be regarded as a matrix B of 1×m where each element is 2 representing a teacher.
As a master of photoshop, your job is to put photo B into photo A with the following constraints:
you are not allowed to split, rotate or scale the picture, but only translation.
each element in matrix B should overlap with an element in A completely, and each teacher should overlap with a blank background, not shelter from a student.
Please calculate the possible ways that you can put photo B into photo A.
大意:给出一个n×n的01矩阵,要用一个1×m的矩阵去覆盖一段 0,问方案数。
签到题:
#include<iostream>
using namespace std;
char a[2010][2010];
char b[2020];
int getsum(int m,int num)
{
return num-m+1;
}
int main()
{
int n,m;
cin>>n>>m;
int sum=0;
for(int i=1;i<=n;i++)
{
int num=0;
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
if(a[i][j]=='0') num++;//记录连续0的长度
if(a[i][j]!='0')
{
if(num>=m) sum+=getsum(m,num);//如果连续0的长度大于老师的人数
num=0;
}
}
if(num>=m) sum+=getsum(m,num);//特判:全部为0时
num=0;
}
for(int i=1;i<=m;i++)
{
cin>>b[i];
}
cout<<sum;
return 0;
}