Determine the Photo Position

题目描述

You have taken the graduation picture of graduates. The picture could be regarded as a matrix A of n×nn \times nn×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×m1 \times m1×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.

输入描述:

The first line contains two integers n,m(1≤n,m≤2000)n,m(1 \le n,m \le 2000)n,m(1≤n,m≤2000) indicating the size of photos A and B. 

In the next $n$ lines,each line contains n{n}n characters of '0' or '1',representing the matrix A.

The last line contains m{m}m characters of '2', representing matrix B. 

输出描述:

Output one integer in a line, indicating the answer.
示例1

输入

5 3
00000
01110
01110
01110
00000
222

输出

6
示例2

输入

3 2
101
010
101
22

输出

0
示例3

输入

3 1
101
010
101
2

输出

4
#include<iostream>
#include<cstdio>
using namespace std;
const int N=2010;
char student[N],teacher[N];
int main()
{
	int a,b;
	int num=1,sum=0;
	int k;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)
	{
		scanf("%s",student); 
		for(int j=0;j<a;j++)
		{
			if(student[j]=='0')
			{
				for(k=j+1;student[k]=='0'&&k<a;k++){
					num++;
				}
				j=k;
                if(num-b>=0)sum=sum+num-b+1;
               // printf("%dxxxx\n",sum);
                num=1;
			}
			
		}
        num=1;
       // printf("%d\n",sum);
		
	}
	scanf("%s",teacher);
	printf("%d\n",sum);
	return 0;
	
}

链接:https://ac.nowcoder.com/acm/contest/11166/D
来源:牛客网
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值