题目链接:http://codeforces.com/problemset/problem/289/B 题目意思:给出一个 n 行 m 列的矩阵和数值 d .通过对矩阵里面的数进行 + d 或者 - d 的操作,是否可以使矩阵上的所有数相等.可以的话输出最少的操作步数,否则输出 -1. 由于矩阵的排列对处理没什么影响,因此不需要用到二维数组存储.接着把矩阵中所有的数从小到大进行排序,要想算出最少的步数,很容易想到应该最中间的数(中位数)靠拢.最关键的是如何判断不能通过对矩阵中的数进行处理使得所有…
[LeetCode]01 Matrix 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/01-matrix/#/description 题目描述: Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell. The distance between two adjacent cells is 1. Example:…
[LeetCode]378. Kth Smallest Element in a Sorted Matrix 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/description/ 题目描述: Given a n x n matrix where each of the rows and columns are sorted in ascen…