2021牛客暑期多校训练营1 D.Determine the Photo Position

题目: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;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值