zoukankan      html  css  js  c++  java
  • 城市天际线--p807

    package Array;
    
    public class p807 {
        /**
         * Example:
         Input: grid = [[3,0,8,4],[2,4,5,7],[9,2,6,3],[0,3,1,0]]
         Output: 35
         Explanation:
         The grid is:
         [ [3, 0, 8, 4],
         [2, 4, 5, 7],
         [9, 2, 6, 3],
         [0, 3, 1, 0] ]
    
         The skyline viewed from top or bottom is: [9, 4, 8, 7]
         The skyline viewed from left or right is: [8, 7, 9, 3]
    
         The grid after increasing the height of buildings without affecting skylines is:
    
         gridNew = [ [8, 4, 8, 7],
         [7, 4, 7, 7],
         [9, 4, 8, 7],
         [3, 3, 3, 3] ]
         */
        public static  void main(String argv[]){
            int grid[][]={{3,0,8,4},{2,4,5,7},{9,2,6,3},{0,3,1,0}};
            p807 temp=new p807();
            System.out.println(temp.maxIncreaseKeepingSkyline(grid));
        }
    
        public  int maxIncreaseKeepingSkyline(int[][] grid) {
            int i,j,sum=0;
            int max1[]=new int[grid.length];
            int max2[]=new int[grid[0].length];
            for(i=0;i<grid[0].length;i++){
                for(j=0;j<grid[0].length;j++){
                    if(grid[i][j]>max1[i])max1[i]=grid[i][j];
                    if(grid[j][i]>max2[i])max2[i]=grid[j][i];
                }
            }
            for(i=0;i<grid.length;i++){
                for(j=0;j<grid[0].length;j++){
                    if(max1[i]<max2[j])sum+=max1[i]-grid[i][j];
                    else{
                        sum+=max2[j]-grid[i][j];
                    }
                }
            }
            return sum;
        }
    
    
    }
  • 相关阅读:
    [NOI2016] 网格
    [十二省联考2019]春节十二响
    wordcloud的方法参数归纳汇总
    选择困难症
    连通能力
    [Tjoi2017]城市
    bzoj3732 Network
    bzoj3252 攻略
    Noip2018旅行
    [HEOI2015]兔子与樱花
  • 原文地址:https://www.cnblogs.com/ming-szu/p/8995427.html
Copyright © 2011-2022 走看看