301218: CF228B. Two Tables

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Two Tables

题意翻译

你有两个矩阵,尺寸分别为 $n_a × m_a$ 和 $n_b × m_b$,每个元素由 $0$ 和 $1$ 构成,下标从 $1$ 开始。 请求出满足 $\sum_{\begin{subarray}{l} \\i,j \end{subarray}} a_{i,j} \cdotp b_{i+x,j+y}$ 的 $x,y$,其中 $1 ≤ i ≤ n_a, 1 ≤ j ≤ m_a, 1 ≤ i + x ≤ n_b, 1 ≤ j + y ≤ m_b$ 。 输入格式: 第一行 $n_a, m_a$ ,下面 $n_a$ 行,每行 $m$ 个数字,都为 $0$ 或 $1$ 。 接着第 $n+2$ 行,输入 $n_b,m_b$ 。下面 $n_b$ 行,每行 $n_b$ 个数字,都为 $0$ 或 $1$ 。 输出格式: 一行,为 $x$ 和 $y$ 。 注意事项: $1≤n_a,m_a,n_b,m_b≤50$ $|x|,|y|≤10^9$

题目描述

You've got two rectangular tables with sizes $ n_{a}×m_{a} $ and $ n_{b}×m_{b} $ 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 $ a_{i,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 $ b_{i,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: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF228B/c8b35e92513beb4ad9da1bdc163ba5b2d1a279ba.png)where the variables $ i,j $ take only such values, in which the expression $ a_{i,j}·b_{i+x,j+y} $ makes sense. More formally, inequalities $ 1<=i<=n_{a},1<=j<=m_{a},1<=i+x<=n_{b},1<=j+y<=m_{b} $ 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.

输入输出格式

输入格式


The first line contains two space-separated integers $ n_{a},m_{a} $ $ (1<=n_{a},m_{a}<=50) $ — the number of rows and columns in the first table. Then $ n_{a} $ lines contain $ m_{a} $ 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 $ n_{b},m_{b} $ $ (1<=n_{b},m_{b}<=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".

输出格式


Print two space-separated integers $ x,y $ $ (|x|,|y|<=10^{9}) $ — a shift with maximum overlap factor. If there are multiple solutions, print any of them.

输入输出样例

输入样例 #1

3 2
01
10
00
2 3
001
111

输出样例 #1

0 1

输入样例 #2

3 3
000
010
000
1 1
1

输出样例 #2

-1 -1

Input

题意翻译

你有两个矩阵,尺寸分别为 $n_a × m_a$ 和 $n_b × m_b$,每个元素由 $0$ 和 $1$ 构成,下标从 $1$ 开始。 请求出满足 $\sum_{\begin{subarray}{l} \\i,j \end{subarray}} a_{i,j} \cdotp b_{i+x,j+y}$ 的 $x,y$,其中 $1 ≤ i ≤ n_a, 1 ≤ j ≤ m_a, 1 ≤ i + x ≤ n_b, 1 ≤ j + y ≤ m_b$ 。 输入格式: 第一行 $n_a, m_a$ ,下面 $n_a$ 行,每行 $m$ 个数字,都为 $0$ 或 $1$ 。 接着第 $n+2$ 行,输入 $n_b,m_b$ 。下面 $n_b$ 行,每行 $n_b$ 个数字,都为 $0$ 或 $1$ 。 输出格式: 一行,为 $x$ 和 $y$ 。 注意事项: $1≤n_a,m_a,n_b,m_b≤50$ $|x|,|y|≤10^9$

加入题单

算法标签: