Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match girl has, please find out a way you can make one square by using up all those matchsticks. You should not break any stick, but you can link them up, a…
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area. For example, given the following matrix: 1 0 1 0 0 1 0 1 1 1 1 1 0 0 1 0 Return 4. Credits:Special thanks to @Freezen for adding this pr…
最主要的思路:1,这条直线就是要把两个正方形的中点链接. 2,注意的特殊情况:中心点重合. 答案: public class Solution { public static void main(String[] args){ Point[] a = {new Point(136,6278),new Point(3958,6278),new Point(3958,2456),new Point(136,2456)}; Point[] b = {new Point(-3898,11132),new…
题目: Given a 2D binary matrix filled with 's and return its area. For example, given the following matrix: Return . 解题思路: 这种包含最大.最小等含优化的字眼时,一般都需要用到动态规划进行求解.本题求面积我们可以转化为求边长,由于是正方形,因此可以根据正方形的四个角的坐标写出动态规划的转移方程式(画一个图,从左上角推到右下角,很容易理解): dp[i][j] = min(dp[i-…
7.5 Given two squares on a two-dimensional plane, find a line that would cut these two squares in half. Assume that the top and the bottom sides of the square run parallel to the x-axis 这道题给了我们两个正方形,让我们求一条可以讲这两个正方形平均分为两个部分的直线,前提是两个正方形都和x轴平行.那么我们首先要知道…
题目: Maximal Square Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area. 样例 For example, given the following matrix: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 Return 4. 解题: 给定一个二维01矩阵,从中找出最大的全…