1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-13 03:11:42 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2025-07-17 00:14:36 +08:00
parent 5808ae7d32
commit dee13a03bd
61 changed files with 17286 additions and 9663 deletions

View File

@@ -0,0 +1,139 @@
<p>表:<code>students</code></p>
<pre>
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| student_id | int |
| student_name | varchar |
| major | varchar |
+--------------+---------+
student_id 是这张表的唯一主键。
每一行包含有关学生及其学术专业的信息。
</pre>
<p>表:<code>study_sessions</code></p>
<pre>
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| session_id | int |
| student_id | int |
| subject | varchar |
| session_date | date |
| hours_studied | decimal |
+---------------+---------+
session_id 是这张表的唯一主键。
每一行代表一个学生针对特定学科的学习时段。
</pre>
<p>编写一个解决方案来找出遵循 <strong>螺旋学习模式</strong> 的学生——即那些持续学习多个学科并按循环周期进行学习的学生。</p>
<ul>
<li>螺旋学习模式意味着学生以重复的顺序学习至少 <code>3</code><strong>不同的学科</strong></li>
<li>模式必须重复 <strong>至少</strong><strong>&nbsp;</strong><code>2</code><strong>&nbsp;个完整周期</strong>(最少&nbsp;<code>6</code>&nbsp;次学习记录)。</li>
<li>两次学习记录必须是间隔不超过&nbsp;<code>2</code>&nbsp;天的 <strong>连续日期</strong></li>
<li>计算 <strong>循环长度</strong>(模式中不同的学科数量)。</li>
<li>计算模式中所有学习记录的 <strong>总学习时长</strong></li>
<li>仅包含循环长度 <strong>至少为&nbsp;</strong><strong>&nbsp;</strong><code>3</code><strong>&nbsp;门学科</strong>&nbsp;的学生。</li>
</ul>
<p>返回结果表按循环长度 <strong>降序</strong>&nbsp;排序,然后按总学习时间 <strong>降序</strong>&nbsp;排序。</p>
<p>结果格式如下所示。</p>
<p>&nbsp;</p>
<p><strong class="example">示例:</strong></p>
<div class="example-block">
<p><strong>输入:</strong></p>
<p>students 表:</p>
<pre class="example-io">
+------------+--------------+------------------+
| student_id | student_name | major |
+------------+--------------+------------------+
| 1 | Alice Chen | Computer Science |
| 2 | Bob Johnson | Mathematics |
| 3 | Carol Davis | Physics |
| 4 | David Wilson | Chemistry |
| 5 | Emma Brown | Biology |
+------------+--------------+------------------+
</pre>
<p>study_sessions 表:</p>
<pre class="example-io">
+------------+------------+------------+--------------+---------------+
| session_id | student_id | subject | session_date | hours_studied |
+------------+------------+------------+--------------+---------------+
| 1 | 1 | Math | 2023-10-01 | 2.5 |
| 2 | 1 | Physics | 2023-10-02 | 3.0 |
| 3 | 1 | Chemistry | 2023-10-03 | 2.0 |
| 4 | 1 | Math | 2023-10-04 | 2.5 |
| 5 | 1 | Physics | 2023-10-05 | 3.0 |
| 6 | 1 | Chemistry | 2023-10-06 | 2.0 |
| 7 | 2 | Algebra | 2023-10-01 | 4.0 |
| 8 | 2 | Calculus | 2023-10-02 | 3.5 |
| 9 | 2 | Statistics | 2023-10-03 | 2.5 |
| 10 | 2 | Geometry | 2023-10-04 | 3.0 |
| 11 | 2 | Algebra | 2023-10-05 | 4.0 |
| 12 | 2 | Calculus | 2023-10-06 | 3.5 |
| 13 | 2 | Statistics | 2023-10-07 | 2.5 |
| 14 | 2 | Geometry | 2023-10-08 | 3.0 |
| 15 | 3 | Biology | 2023-10-01 | 2.0 |
| 16 | 3 | Chemistry | 2023-10-02 | 2.5 |
| 17 | 3 | Biology | 2023-10-03 | 2.0 |
| 18 | 3 | Chemistry | 2023-10-04 | 2.5 |
| 19 | 4 | Organic | 2023-10-01 | 3.0 |
| 20 | 4 | Physical | 2023-10-05 | 2.5 |
+------------+------------+------------+--------------+---------------+
</pre>
<p><strong>输出:</strong></p>
<pre class="example-io">
+------------+--------------+------------------+--------------+-------------------+
| student_id | student_name | major | cycle_length | total_study_hours |
+------------+--------------+------------------+--------------+-------------------+
| 2 | Bob Johnson | Mathematics | 4 | 26.0 |
| 1 | Alice Chen | Computer Science | 3 | 15.0 |
+------------+--------------+------------------+--------------+-------------------+
</pre>
<p><strong>解释:</strong></p>
<ul>
<li><strong>Alice Chen (student_id = 1):</strong>
<ul>
<li>学习序列Math → Physics → Chemistry → Math → Physics → Chemistry</li>
<li>模式3 门学科MathPhysicsChemistry重复 2 个完整周期</li>
<li>连续日期:十月 1-6没有超过 2 天的间隔</li>
<li>循环长度3 门学科</li>
<li>总时间2.5 + 3.0 + 2.0 + 2.5 + 3.0 + 2.0 = 15.0 小时</li>
</ul>
</li>
<li><strong>Bob Johnson (student_id = 2):</strong>
<ul>
<li>学习序列Algebra → Calculus → Statistics → Geometry → Algebra → Calculus → Statistics → Geometry</li>
<li>模式4 门学科AlgebraCalculusStatisticsGeometry重复 2 个完整周期</li>
<li>连续日期:十月 1-8没有超过 2 天的间隔</li>
<li>循环长度4 门学科</li>
<li>总时间4.0 + 3.5 + 2.5 + 3.0 + 4.0 + 3.5 + 2.5 + 3.0 = 26.0&nbsp;小时</li>
</ul>
</li>
<li><strong>未包含学生:</strong>
<ul>
<li>Carol Davis (student_id = 3):仅 2 门学科(生物,化学)- 未满足至少 3 门学科的要求</li>
<li>David Wilson (student_id = 4):仅 2 次学习课程,间隔 4 天 - 不符合连续日期要求</li>
<li>Emma Brown (student_id = 5):没有记录学习课程</li>
</ul>
</li>
</ul>
<p>结果表以 cycle_length 降序排序,然后以 total_study_hours 降序排序。</p>
</div>