LC 835. Image Overlap
Two images A
and B
are given, represented as binary, square matrices of the same size. (A binary matrix has only 0s and 1s as values.)
We translate one image however we choose (sliding it left, right, up, or down any number of units), and place it on top of the other image. After, the overlap of this translation is the number of positions that have a 1 in both images.
(Note also that a translation does not include any kind of rotation.)
What is the largest possible overlap?
Example 1:
Input: A = [[1,1,0],
[0,1,0],
[0,1,0]]
B = [[0,0,0],
[0,1,1],
[0,0,1]]
Output: 3
Explanation: We slide A to right by 1 unit and down by 1 unit.
Notes:
1 <= A.length = A[0].length = B.length = B[0].length <= 30
0 <= A[i][j], B[i][j] <= 1
Runtime: 103 ms, faster than 42.68% of Java online submissions for Image Overlap.
注意,求两个点的向量差值,唯一表示要把坐标分开来,
这一题中,坐标小于30,所以La,Lb中add了i/N * 100 + i% N, i/N 和 i % N分别是横纵坐标。
最后的表示是一个4位数,xxxx。前两位是横坐标,后两位是纵坐标。
class Solution { public int largestOverlap(int[][] A, int[][] B){
int N = A.length;
List<Integer> La = new ArrayList<>();
List<Integer> Lb = new ArrayList<>();
HashMap<Integer, Integer> dist = new HashMap<>();
for(int i=; i<N*N; i++) if(A[i/N][i%N] == ) La.add(i/N* + i%N);
for(int j=; j<N*N; j++) if(B[j/N][j%N] == ) Lb.add(j/N* + j%N);
for(int i : La){
for(int j : Lb){
dist.put(i - j, dist.getOrDefault(i-j, ) + );
}
}
int ret = ;
for(int i : dist.values()) ret = Math.max(i, ret);
return ret;
}
}
LC 835. Image Overlap的更多相关文章
- 835. Image Overlap
Two images A and B are given, represented as binary, square matrices of the same size. (A binary ma ...
- 【leetcode】835. Image Overlap
题目如下: 解题思路:抛开移动的过程只看移动完成的结果,记图片左上角为顶点,正方形边长为board,要使得两个图片要有重叠,那么一定其中一张图片的顶点和另外一张图片的某一个点重合.假设图片A的顶点A( ...
- 835. Image Overlap —— weekly contest 84
Image Overlap Two images A and B are given, represented as binary, square matrices of the same size. ...
- 【LeetCode】835. Image Overlap 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 算法与数据结构基础 - 数组(Array)
数组基础 数组是最基础的数据结构,特点是O(1)时间读取任意下标元素,经常应用于排序(Sort).双指针(Two Pointers).二分查找(Binary Search).动态规划(DP)等算法.顺 ...
- All LeetCode Questions List 题目汇总
All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...
- The Daligner Overlap Library
/************************************************************************************\ * * * Copyrig ...
- [LeetCode] Image Overlap 图像重叠
Two images A and B are given, represented as binary, square matrices of the same size. (A binary ma ...
- 836. Rectangle Overlap 矩形重叠
[抄题]: A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of i ...
随机推荐
- 运行tomcat7w.exe提示指定的服务未安装 解决办法
一.问题重现点击bin下tomcat7w.exe出现如下提示:提示指定的服务未安装 二.原因分析tomcat7.exe和tomcat7w.exe要起作用必须先为这两个文件安装服务.其中tomcat7. ...
- 修改一张MyISAM表row_format为fixed为InnoDB表报错处理
最近优化GTID模式下事务表和非事务表更新报错处理时,发现某几张表更改存储引擎为InnoDB报错如下: mysql> alter table sc_xxx_video_xxxxengine = ...
- (一)Android jni打印到logcat
#include <stdio.h> #include <android/log.h> int main(void) { int a = 0x10,b = 0x20; __an ...
- web开发:javascript动画
一.鼠标事件 二.js盒模型 三.鼠标拖拽 四.键盘事件 五.其他时间应用 六.定时器 七.定时器案例 八.随机数 一.鼠标事件 <!DOCTYPE html> <html> ...
- Lambda表达式语法进一步巩固
上一次已经初步使用到了Lambda表达式了,这次再次对它的语法进行一下巩固,因为它实在是太重要的,所以多花时间彻底理解它是非常有必要的. 在"Java8 in Action"一书中 ...
- FFmpeg常用命令学习笔记(四)处理原始数据命令
处理原始数据命令 通过音视频设备采集的.没有经过任何加工的数据叫原始数据,而像我们平时播放的比如mp4文件是压缩后的数据.视频原始数据是YUV格式,音频原始数据是PCM格式.FFmpeg可以从封装格 ...
- mysql 5.6zip版本的卸载与5.7 zip 版本的安装
链接:http://www.imooc.com/article/10359 一 安装环境windows 7 旗舰版mysql-5.6.17-winx64.zip 二 安装过程1.去官网下载mysql- ...
- Orchard Core 使用工作流处理页面提交
上一篇文章中:Orchard Core 使用工作流处理审批和创建内容项 我们介绍了如何使用工作流处理审批,通过此文章我们了解到工作流的简单使用.但提交数据来自于Postman 本次文章我将演示如何从页 ...
- Jmeter设置集合点(并发测试)
什么是集合点? 让所有请求在不满足条件的时候处于等待状态. 如何实现? 使用jmeter中的同步计时器Synchronizing Timer来实现 集合点的位置 因为集合点是在取样器sampler(例 ...
- eclipse调试断点
1.条件断点 如果你不知道如何添加断点,只需点击左边面板(行号前面)断点即被创建.在调试界面中,“断点”视图会把所有被创建的断点列出来.我们可以给它加一个布尔条件,也就是说,该断点会被激活并且如果布尔 ...