On a N * N grid, we place some 1 * 1 * 1 cubes that are axis-aligned with the x, y, and z axes.

Each value v = grid[i][j] represents a tower of v cubes placed on top of grid cell (i, j).

Now we view the projection of these cubes onto the xy, yz, and zx planes.

A projection is like a shadow, that maps our 3 dimensional figure to a 2 dimensional plane.

Here, we are viewing the "shadow" when looking at the cubes from the top, the front, and the side.

Return the total area of all three projections.

 
 
 
 

Example 1:

Input: [[2]]
Output: 5

Example 2:

Input: [[1,2],[3,4]]
Output: 17
Explanation:
Here are the three projections ("shadows") of the shape made with each axis-aligned plane.

Example 3:

Input: [[1,0],[0,2]]
Output: 8

Example 4:

Input: [[1,1,1],[1,0,1],[1,1,1]]
Output: 14

Example 5:

Input: [[2,2,2],[2,1,2],[2,2,2]]
Output: 21

Note:

  • 1 <= grid.length = grid[0].length <= 50
  • 0 <= grid[i][j] <= 50

This problem is just like the problem 807. We just need to find the max element in each row and column and find the number of nonzero elements. Then the sum of them is the answer.

class Solution:
def projectionArea(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
""" rAf=sum([max(r) for r in grid])+sum([max(c) for c in zip(*grid)]) m=len(grid)
n=len(grid[0]) num=0 for r in grid:
num+=r.count(0) return (m*n-num)+rAf

  

[LeetCode&Python] Problem 883. Projection Area of 3D Shapes的更多相关文章

  1. [LeetCode&Python] Problem 892. Surface Area of 3D Shapes

    On a N * N grid, we place some 1 * 1 * 1 cubes. Each value v = grid[i][j] represents a tower of v cu ...

  2. 【Leetcode_easy】883. Projection Area of 3D Shapes

    problem 883. Projection Area of 3D Shapes 参考 1. Leetcode_easy_883. Projection Area of 3D Shapes; 完

  3. 883. Projection Area of 3D Shapes

    问题 NxN个格子中,用1x1x1的立方体堆叠,grid[i][j]表示坐标格上堆叠的立方体个数,求三视图面积. Input: [[1,2],[3,4]] Output: 17 Explanation ...

  4. 【LeetCode】883. Projection Area of 3D Shapes 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数学计算 日期 题目地址:https://leetc ...

  5. [LeetCode] 883. Projection Area of 3D Shapes 三维物体的投影面积

    On a N * N grid, we place some 1 * 1 * 1 cubes that are axis-aligned with the x, y, and z axes. Each ...

  6. LeetCode 883 Projection Area of 3D Shapes 解题报告

    题目要求 On a N * N grid, we place some 1 * 1 * 1 cubes that are axis-aligned with the x, y, and z axes. ...

  7. 【leetcode】883. Projection Area of 3D Shapes

    题目如下: 解题思路:分别求出所有立方体的个数,各行的最大值之和,各列的最大值之和.三者相加即为答案. 代码如下: class Solution(object): def projectionArea ...

  8. [Swift]LeetCode883. 三维形体投影面积 | Projection Area of 3D Shapes

    On a N * N grid, we place some 1 * 1 * 1 cubes that are axis-aligned with the x, y, and z axes. Each ...

  9. Leetcode883.Projection Area of 3D Shapes三维形体投影面积

    在 N * N 的网格中,我们放置了一些与 x,y,z 三轴对齐的 1 * 1 * 1 立方体. 每个值 v = grid[i][j] 表示 v 个正方体叠放在单元格 (i, j) 上. 现在,我们查 ...

随机推荐

  1. php 四种基础排序

    1. 冒泡排序算法 *     思路分析:法如其名,就是像冒泡一样,每次从数组当中 冒一个最大的数出来.  *     比如:2,4,1    // 第一次 冒出的泡是4  *             ...

  2. Codeforces D - Ithea Plays With Chtholly

    D - Ithea Plays With Chtholly 思路:考虑每个位置最多被替换c/2次 那么折半考虑,如果小于c/2,从左往右替换,大于c/2总右往左替换,只有小于这个数(从左往右)或者大于 ...

  3. Redis之哈希类型命令

    Hash(哈希) Redis hash 是一个string类型的field和value的映射表,hash特别适合用于存储对象. Redis 中每个 hash 可以存储 232 - 1 键值对(40多亿 ...

  4. python--HTTPClient接口测试踩坑

    1.今天下午做接口测试的时候遇到一个奇怪的问题:原因不明 requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisc ...

  5. 『Scrapy』爬取腾讯招聘网站

    分析爬取对象 初始网址, http://hr.tencent.com/position.php?@start=0&start=0#a (可选)由于含有多页数据,我们可以查看一下这些网址有什么相 ...

  6. string类的用法笔记

    要想使用标准C++中string类,必须要包含 #include <string>// 注意是<string>,不是<string.h>,带.h的是C语言中的头文件 ...

  7. bfs,dfs区别

    一般来说用DFS解决的问题都可以用BFS来解决. DFS(深搜的同时考虑回溯) bfs=队列,入队列,出队列:dfs=栈,压栈,出栈 bfs是按一层一层来访问的,所以适合有目标求最短路的步数,你想想层 ...

  8. POJ-3259 Wormholes(判断负环、模板)

    Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes ...

  9. DATEADD 和 CAST 函数

    where cast(soh.orderdate as date)=cast(dateadd(day,-1,getdate()) as date) 这一代码在sql 2005 不适用,使用conver ...

  10. Unicode与UTF-8,UTF-16

    Unicode(UTF-8, UTF-16)令人混淆的概念 为啥需要Unicode 我们知道计算机其实挺笨的,它只认识0101这样的字符串,当然了我们看这样的01串时肯定会比较头晕的,所以很多时候为了 ...