A8727 | Two Tables
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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:
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.
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 $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".
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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted