Codeforces Round #141 (Div. 2) B. Two Tables 枚举

本文探讨了深度学习技术在音视频处理、AR特效、AI音视频处理等领域的应用,包括图像处理、音视频编解码、自然语言处理、区块链与隐私计算等关键技术。通过实际案例分析,展示了如何利用这些技术解决复杂问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

You've got two rectangular tables with sizes na × ma and nb × mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j.

We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y)value:

where the variables i, j take only such values, in which the expression ai, j·bi + x, j + y makes sense. More formally, inequalities 1 ≤ i ≤ na, 1 ≤ j ≤ ma, 1 ≤ i + x ≤ nb, 1 ≤ j + y ≤ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0.

Your task is to find the shift with the maximum overlap factor among all possible shifts.

Input

The first line contains two space-separated integers na, ma (1 ≤ na, ma ≤ 50) — the number of rows and columns in the first table. Thenna lines contain ma characters each — the elements of the first table. Each character is either a "0", or a "1".

The next line contains two space-separated integers nb, mb (1 ≤ nb, mb ≤ 50) — the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table.

It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1".

Output

Print two space-separated integers x, y (|x|, |y| ≤ 109) — a shift with maximum overlap factor. If there are multiple solutions, print any of them.

Sample test(s)
input
3 2
01
10
00
2 3
001
111
output
0 1
input
3 3
000
010
000
1 1
1
output
-1 -1

    题意:给两个01数字矩阵,求最多重合的1时第二个相对于第一个数字矩阵的位置。

    枚举搞的,效率还可以。

  My code:

//STATUS:C++_AC_109MS_196100KB  
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
using namespace std;
const int MAX=10010,INF=200000000;
#define lson l,mid<<1,k<<1
#define rson mid<<1|1,r,k<<1|1

int na,ma,nb,mb;
char a[MAX][MAX],b[MAX][MAX];
int get(int x,int y){
	int i,j,s=0,nx,ny;
	for(i=0;i<na;i++){
		for(j=0;j<ma;j++){
			nx=i+x,ny=j+y;
			if(nx>=0&&nx<nb && ny>=0&&ny<mb
				&& b[nx][ny]=='1' && a[i][j]=='1')
				s++;
		}
	}
	return s;
}

int main()
{
//	freopen("in.txt","r",stdin);
	int i,j,t,max,x,y;
	while(~scanf("%d%d",&na,&ma))
	{
		for(i=0;i<na;i++)
			scanf("%s",a[i]);
		scanf("%d%d",&nb,&mb);
		for(i=0;i<nb;i++)
			scanf("%s",b[i]);

		max=0;
		for(i=-na+1;i<nb;i++){
			for(j=-ma+1;j<mb;j++){
				t=get(i,j);
				if(t>max){
					max=t;
					x=i,y=j;
				}
			}
		}

		printf("%d %d\n",x,y);
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值