1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/安排电影院座位 [cinema-seat-allocation].html
2022-03-29 12:43:11 +08:00

44 lines
2.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/03/21/cinema_seats_1.png" style="height: 149px; width: 400px;"></p>
<p>如上图所示,电影院的观影厅中有 <code>n</code>&nbsp;行座位,行编号从 1&nbsp;<code>n</code>&nbsp;,且每一行内总共有 10 个座位,列编号从 1 到 10 。</p>
<p>给你数组&nbsp;<code>reservedSeats</code>&nbsp;,包含所有已经被预约了的座位。比如说,<code>researvedSeats[i]=[3,8]</code>&nbsp;,它表示第&nbsp;<strong>3</strong>&nbsp;行第&nbsp;<strong>8</strong>&nbsp;个座位被预约了。</p>
<p>请你返回&nbsp;<strong>最多能安排多少个 4 人家庭</strong>&nbsp;。4 人家庭要占据&nbsp;<strong>同一行内连续&nbsp;</strong>的 4 个座位。隔着过道的座位(比方说 [3,3] 和 [3,4])不是连续的座位,但是如果你可以将 4 人家庭拆成过道两边各坐 2 人,这样子是允许的。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/03/21/cinema_seats_3.png" style="height: 96px; width: 400px;"></p>
<pre><strong>输入:</strong>n = 3, reservedSeats = [[1,2],[1,3],[1,8],[2,6],[3,1],[3,10]]
<strong>输出:</strong>4
<strong>解释:</strong>上图所示是最优的安排方案,总共可以安排 4 个家庭。蓝色的叉表示被预约的座位,橙色的连续座位表示一个 4 人家庭。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>n = 2, reservedSeats = [[2,1],[1,8],[2,6]]
<strong>输出:</strong>2
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>n = 4, reservedSeats = [[4,3],[1,4],[4,6],[1,7]]
<strong>输出:</strong>4
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 10^9</code></li>
<li><code>1 &lt;=&nbsp;reservedSeats.length &lt;= min(10*n, 10^4)</code></li>
<li><code>reservedSeats[i].length == 2</code></li>
<li><code>1&nbsp;&lt;=&nbsp;reservedSeats[i][0] &lt;= n</code></li>
<li><code>1 &lt;=&nbsp;reservedSeats[i][1] &lt;= 10</code></li>
<li>所有&nbsp;<code>reservedSeats[i]</code> 都是互不相同的。</li>
</ul>