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 <= 300 <= 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 ...
随机推荐
- Jmeter服务器压力测试使用说明
Jmeter服务器压力测试使用说明 Apache JMeter是Apache组织开发的基于Java的压力测试工具. 官方地址:http://jmeter.apache.org/download_jme ...
- C#验证控件使用方法及常用正则表达式例析(转)
ASP.NET为开发人员提供了一整套完整的服务器控件来验证用户输入的信息是否有效.这些控件如下: 1.RequiredFieldValidator:验证一个必填字段,如果这个字段没填,那么,将不能提交 ...
- navicat for mysql 下载安装教程
Navicat是一套快速.可靠并价格相当便宜的数据库管理工具,专为简化数据库的管理及降低系统管理成本而设.它的设计符合数据库管理员.开发人员及中小企业的需要.Navicat 是以直觉化的图形用户界面而 ...
- MySQL安装步骤及环境变量配置
MySQL安装 MySQL下载地址:http://dev.mysql.com/downloads/installer/1:首先进入的是安装引导界面2:然后进入的是类型选择界面,这里有3个类型:Typi ...
- OpenJudge POJ C19C 贪心
https://cn.vjudge.net/contest/309482#problem/C #include<bits/stdc++.h> using namespace std; ty ...
- Java&Selenium&TestNG&ZTestReport 自动化测试并生成HTML自动化测试报告
一.摘要 本篇博文将介绍如何借助ZTestReport和HTML模版,生成HTML测试报告的ZTestReport 源码Clone地址为 https://github.com/zhangfei1984 ...
- JDK的收费问题
关于JDK是否收费,我也有过疑问,查了一些资料,就在这里做一个简要的说明. 首先要明白JDK的发布模型.两年多以前,2017年9月21日,伴随着JDK9的发布,JDK就开启了新的发布模式(如下图所示) ...
- JDBC下
存储过程名字前面一定要加一个sp,代表是存储过程 nofilter:没有过滤器,没有参数 )) BEGIN IF sp_name IS NULL OR sp_name='' THEN SELECT * ...
- Webpack v4.8.3 快速入门指南
一.进入 https://webpack.docschina.org/ 官方文档,点击 "文档" 进入 文档页面,文档中包含 “概念,配置,API,指南,LOADERS,插件&q ...
- p4434 [COCI2017-2018#2] Usmjeri
思路 并查集的好题 考虑到求满足条件限制的方案数,显然观察样例可知结果就是2^x,x是互不影响的边的集合数量 然后考虑如何求互不影响的边的集合数量 可以使用并查集,用i和i+n表示这个点的父亲连向它的 ...