<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>projection Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/projection/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/projection/</link>
	<description></description>
	<lastBuildDate>Sun, 05 Aug 2018 03:06:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>projection Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/projection/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 887. Projection Area of 3D Shapes</title>
		<link>https://zxi.mytechroad.com/blog/geometry/leetcode-887-projection-area-of-3d-shapes/</link>
					<comments>https://zxi.mytechroad.com/blog/geometry/leetcode-887-projection-area-of-3d-shapes/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 05 Aug 2018 03:06:30 +0000</pubDate>
				<category><![CDATA[Geometry]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[historgram]]></category>
		<category><![CDATA[projection]]></category>
		<category><![CDATA[shadow]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=3432</guid>

					<description><![CDATA[<p>Problem 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&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/geometry/leetcode-887-projection-area-of-3d-shapes/">花花酱 LeetCode 887. Projection Area of 3D Shapes</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1>Problem</h1>
<p>On a <code>N * N</code> grid, we place some <code>1 * 1 * 1 </code>cubes that are axis-aligned with the x, y, and z axes.</p>
<p>Each value <code>v = grid[i][j]</code> represents a tower of <code>v</code> cubes placed on top of grid cell <code>(i, j)</code>.</p>
<p>Now we view the <em>projection</em> of these cubes onto the xy, yz, and zx planes.</p>
<p>A projection is like a shadow, that maps our 3 dimensional figure to a 2 dimensional plane.</p>
<p>Here, we are viewing the &#8220;shadow&#8221; when looking at the cubes from the top, the front, and the side.</p>
<p>Return the total area of all three projections.</p>
<p><strong>Example 1:</strong></p>
<pre class="crayon:false"><strong>Input: </strong><span id="example-input-1-1">[[2]]</span>
<strong>Output: </strong><span id="example-output-1">5</span>
</pre>
<div>
<p><strong>Example 2:</strong></p>
<pre class="crayon:false"><strong>Input: </strong><span id="example-input-2-1">[[1,2],[3,4]]</span>
<strong>Output: </strong><span id="example-output-2">17</span>
<strong>Explanation: </strong>
Here are the three projections ("shadows") of the shape made with each axis-aligned plane.
<img src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/08/02/shadow.png" alt="" />
</pre>
<div>
<p><strong>Example 3:</strong></p>
<pre class="crayon:false"><strong>Input: </strong><span id="example-input-3-1">[[1,0],[0,2]]</span>
<strong>Output: </strong><span id="example-output-3">8</span>
</pre>
<div>
<p><strong>Example 4:</strong></p>
<pre class="crayon:false"><strong>Input: </strong><span id="example-input-4-1">[[1,1,1],[1,0,1],[1,1,1]]</span>
<strong>Output: </strong><span id="example-output-4">14</span>
</pre>
<div>
<p><strong>Example 5:</strong></p>
<pre class="crayon:false"><strong>Input: </strong><span id="example-input-5-1">[[2,2,2],[2,1,2],[2,2,2]]</span>
<strong>Output: </strong><span id="example-output-5">21</span>
</pre>
<div>
<div>
<div>
<p><strong>Note:</strong></p>
<ul>
<li><code>1 &lt;= grid.length = grid[0].length &lt;= 50</code></li>
<li><code>0 &lt;= grid[i][j] &lt;= 50</code></li>
</ul>
<h1><strong>Solution: Brute Force</strong></h1>
<p>Sum of max heights for each cols / rows + # of non-zero-height bars.</p>
<p>Time complexity: O(mn)</p>
<p>Space complexity: O(1)</p>
<p>C++</p><pre class="crayon-plain-tag">// Author: Huahua
// Running time : 4 ms
class Solution {
public:
  int projectionArea(vector&lt;vector&lt;int&gt;&gt;&amp; grid) {
    int n = grid.size();    
    int m = grid[0].size();
    int ans = 0;
    for (int i = 0; i &lt; n; ++i) {
      int h = 0;
      for (int j = 0; j &lt; m; ++j) {
        h = max(h, grid[i][j]);
        if (grid[i][j] != 0) ++ans;
      }
      ans += h;      
    }
    for (int j = 0; j &lt; m; ++j) {
      int h = 0;
      for (int i = 0; i &lt; n; ++i)
        h = max(h, grid[i][j]);
      ans += h;      
    }
    return ans;
  }
};</pre><p>&nbsp;</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/geometry/leetcode-887-projection-area-of-3d-shapes/">花花酱 LeetCode 887. Projection Area of 3D Shapes</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/geometry/leetcode-887-projection-area-of-3d-shapes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
