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)/参加考试的最大学生数 [maximum-students-taking-exam].html

56 lines
2.3 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>给你一个&nbsp;<code>m&nbsp;* n</code>&nbsp;的矩阵 <code>seats</code>&nbsp;表示教室中的座位分布。如果座位是坏的(不可用),就用&nbsp;<code>'#'</code>&nbsp;表示;否则,用&nbsp;<code>'.'</code>&nbsp;表示。</p>
<p>学生可以看到左侧、右侧、左上、右上这四个方向上紧邻他的学生的答卷,但是看不到直接坐在他前面或者后面的学生的答卷。请你计算并返回该考场可以容纳的同时参加考试且无法作弊的&nbsp;<strong>最大&nbsp;</strong>学生人数。</p>
<p>学生必须坐在状况良好的座位上。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/02/09/image.png" style="height: 197px; width: 339px;" /></p>
<pre>
<strong>输入:</strong>seats = [["#",".","#","#",".","#"],
&nbsp; [".","#","#","#","#","."],
&nbsp; ["#",".","#","#",".","#"]]
<strong>输出:</strong>4
<strong>解释:</strong>教师可以让 4 个学生坐在可用的座位上,这样他们就无法在考试中作弊。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>seats = [[".","#"],
&nbsp; ["#","#"],
&nbsp; ["#","."],
&nbsp; ["#","#"],
&nbsp; [".","#"]]
<strong>输出:</strong>3
<strong>解释:</strong>让所有学生坐在可用的座位上。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>seats = [["#",".","<strong>.</strong>",".","#"],
&nbsp; ["<strong>.</strong>","#","<strong>.</strong>","#","<strong>.</strong>"],
&nbsp; ["<strong>.</strong>",".","#",".","<strong>.</strong>"],
&nbsp; ["<strong>.</strong>","#","<strong>.</strong>","#","<strong>.</strong>"],
&nbsp; ["#",".","<strong>.</strong>",".","#"]]
<strong>输出:</strong>10
<strong>解释:</strong>让学生坐在第 1、3 和 5 列的可用座位上。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>seats</code>&nbsp;只包含字符&nbsp;<code>'.'&nbsp;</code><code>'#'</code></li>
<li><code>m ==&nbsp;seats.length</code></li>
<li><code>n ==&nbsp;seats[i].length</code></li>
<li><code>1 &lt;= m &lt;= 8</code></li>
<li><code>1 &lt;= n &lt;= 8</code></li>
</ul>