<?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>pyramid Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/pyramid/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/pyramid/</link>
	<description></description>
	<lastBuildDate>Sun, 24 Jan 2021 06:57: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>pyramid Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/pyramid/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1739. Building Boxes</title>
		<link>https://zxi.mytechroad.com/blog/geometry/leetcode-1739-building-boxes/</link>
					<comments>https://zxi.mytechroad.com/blog/geometry/leetcode-1739-building-boxes/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 24 Jan 2021 06:48:28 +0000</pubDate>
				<category><![CDATA[Geometry]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[pyramid]]></category>
		<category><![CDATA[triangle]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=8034</guid>

					<description><![CDATA[<p>You have a cubic storeroom where the width, length, and height of the room are all equal to&#160;n&#160;units. You are asked to place&#160;n&#160;boxes in this&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/geometry/leetcode-1739-building-boxes/">花花酱 LeetCode 1739. Building Boxes</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>You have a cubic storeroom where the width, length, and height of the room are all equal to&nbsp;<code>n</code>&nbsp;units. You are asked to place&nbsp;<code>n</code>&nbsp;boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes:</p>



<ul><li>You can place the boxes anywhere on the floor.</li><li>If box&nbsp;<code>x</code>&nbsp;is placed on top of the box&nbsp;<code>y</code>, then each side of the four vertical sides of the box&nbsp;<code>y</code>&nbsp;<strong>must</strong>&nbsp;either be adjacent to another box or to a wall.</li></ul>



<p>Given an integer&nbsp;<code>n</code>, return<em>&nbsp;the&nbsp;<strong>minimum</strong>&nbsp;possible number of boxes touching the floor.</em></p>



<p><strong>Example 1:</strong></p>



<figure class="wp-block-image"><img src="https://assets.leetcode.com/uploads/2021/01/04/3-boxes.png" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> n = 3
<strong>Output:</strong> 3
<strong>Explanation:</strong> The figure above is for the placement of the three boxes.
These boxes are placed in the corner of the room, where the corner is on the left side.
</pre>



<p><strong>Example 2:</strong></p>



<figure class="wp-block-image"><img src="https://assets.leetcode.com/uploads/2021/01/04/4-boxes.png" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> n = 4
<strong>Output:</strong> 3
<strong>Explanation:</strong> The figure above is for the placement of the four boxes.
These boxes are placed in the corner of the room, where the corner is on the left side.
</pre>



<p><strong>Example 3:</strong></p>



<figure class="wp-block-image"><img src="https://assets.leetcode.com/uploads/2021/01/04/10-boxes.png" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> n = 10
<strong>Output:</strong> 6
<strong>Explanation:</strong> The figure above is for the placement of the ten boxes.
These boxes are placed in the corner of the room, where the corner is on the back side.</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li></ul>



<p></p>



<h2><strong>Solution: Geometry</strong></h2>



<p>Step 1: Build a largest pyramid that has less then n cubes, whose base area is d*(d+1) / 2<br>Step 2: Build a largest triangle with cubes left, whose base area is l, l*(l + 1) / 2 &gt;= left</p>



<p>Time complexity: O(n^(1/3))<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  int minimumBoxes(int n) {
    int d = 0;
    int l = 0;
    while (n - (d + 1) * (d + 2) / 2 &gt; 0) {
      n -= (d + 1) * (d + 2) / 2;
      ++d;
    }
    while (n &gt; 0) n -= ++l;
    return d * (d + 1) / 2 + l;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/geometry/leetcode-1739-building-boxes/">花花酱 LeetCode 1739. Building Boxes</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-1739-building-boxes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
