diff --git a/Html/.log b/Html/.log index 21da602..e208016 100644 --- a/Html/.log +++ b/Html/.log @@ -3366,3 +3366,15 @@ disconnect success stop code-server success VSCode client disconnected Disconnect reason:transport close 59.78.194.184,127.0.0.1 - - [13/Oct/2025 20:52:40] "GET /socket.io/?user_uuid=user_5eb582cc-8220-452e-827e-e508b3c108b0&folder=%2Fhome%2Fcake%2F68bacdfadf5aeae0912f7f18%2F%E7%AC%AC%E4%B8%80%E5%91%A8%2F%E6%95%88%E7%8E%87%E7%9A%84%E9%87%8D%E8%A6%81%E6%80%A7%E4%B8%8E%E5%AE%9E%E8%B7%B5%E9%AA%8C%E8%AF%81&EIO=4&transport=websocket&sid=ECCFFenBGBtqjcdYAAAQ HTTP/1.1" 200 0 46.588582 + * Restarting with stat + * Debugger is active! + * Debugger PIN: 797-256-719 +(300923) wsgi starting up on http://127.0.0.1:5551 + * Restarting with stat + * Debugger is active! + * Debugger PIN: 797-256-719 +(303256) wsgi starting up on http://127.0.0.1:5551 +[2025-10-16 14:11:31,401] INFO in __init__: Shutting down gracefully (atexit)... +[2025-10-16 14:11:31,762] INFO in __init__: Cleanup finished (atexit). +[2025-10-16 14:11:31,452] INFO in __init__: Shutting down gracefully (atexit)... +[2025-10-16 14:11:31,925] INFO in __init__: Cleanup finished (atexit). diff --git a/Html/apps/static/68bacdfadf5aeae0912f7f18-第二周-算法设计范式:分而治之与归并排序.html b/Html/apps/static/68bacdfadf5aeae0912f7f18-第二周-算法设计范式:分而治之与归并排序.html new file mode 100644 index 0000000..b89740f --- /dev/null +++ b/Html/apps/static/68bacdfadf5aeae0912f7f18-第二周-算法设计范式:分而治之与归并排序.html @@ -0,0 +1,145 @@ + + + + + + Document + + + + + + + +

算法设计范式:分而治之与归并排序

+
+

Auto-generated at 2025-09-22 15:38

+
+

算法设计范式:分而治之与归并排序

+

第一关:理论探究:分而治之的力量

+

案例背景:智慧城市交通优化系统

+

在上周的工作中,你已经实现并分析了插入排序在交通数据处理中的性能。虽然它在数据量较小或基本有序的情况下表现不错,但在应对大规模拥堵(逆序数据)时,其性能瓶颈非常明显。本周,你的项目经理(Agent)将向你介绍一种更高效的算法设计思想——“分而治之”,并要求你掌握其代表算法:归并排序。

+

任务:理解与分析

+
场景介绍
+

你的经理告诉你,归并排序(Merge Sort)是解决大规模排序问题的利器。在投入编码之前,你必须先从理论上理解它为何如此高效。

+
思考题
+

请与右侧的Agent(你的项目经理)对话,清晰地回答以下问题,以证明你已理解核心思想:

+
    +
  1. +

    分治思想:根据课程资料,请解释什么是“分而治之”(Divide-and-Conquer)设计范式?它包含哪三个基本步骤?

    +
  2. +
  3. +

    递推关系:归并排序的时间复杂度可以用递推式 T(n)=2T(n/2)+Θ(n) 来表示。请解释这个式子各部分的含义:

    + +
  4. +
  5. +

    效率对比:你的同事认为,插入排序经过极致优化后,处理n个数据的耗时为 0.1n^2;而归并排序由于递归和合并开销,耗时为 1000nlog_2n。在处理超大规模城市交通数据时(即n趋于无穷大时),哪个算法最终会胜出?请从渐进增长的角度解释你的理由。

    +
  6. +
  7. +

    增长排序:将下列函数的渐进增长率从低到高排序,并将它们划分到等价类(即 Θ 关系相同的函数)。这有助于你理解不同算法效率的所在层级。

    + +
  8. +
+

第二关:编程实践:实现归并排序

+

任务:编码与对比

+
场景介绍
+

现在你已经从理论上理解了归并排序的威力。是时候亲手实现它,并与上周的插入排序进行一次性能上的正面较量了!

+
题目:实现归并排序并对比性能
+

你需要实现归并排序的核心函数,并利用上周的测试框架来直观对比它与插入排序在处理不同交通数据时的表现。

+
代码框架
+

在下方代码编辑区,完成 merge_sort(arr)merge(left, right) 两个函数的实现。

+
import random
+import time
+
+#上周实现的插入排序(用于对比)
+def insertion_sort(arr):
+    for i in range(1, len(arr)):
+        key = arr[i]
+        j = i - 1
+        while j >= 0 and arr[j] > key:
+            arr[j + 1] = arr[j]
+            j -= 1
+        arr[j + 1] = key
+    return arr
+
+#--- 本周任务:请在下方实现归并排序 ---
+
+def merge_sort(arr):
+    """
+    实现归并排序算法
+    参数arr: 待排序的交通数据数组
+    返回: 一个新的、排序好的数组
+    """
+    # TODO: 实现归并排序的递归逻辑
+    # 提示:当数组元素个数小于等于1时,递归终止
+    
+
+def merge(left, right):
+    """
+    合并两个已排序的子数组
+    参数left: 左侧已排序数组
+    参数right: 右侧已排序数组
+    返回: 合并后的一个有序数组
+    """
+  
+
+#--- 测试与对比部分 ---
+
+def measure_performance(sort_func, data):
+    start_time = time.perf_counter_ns()
+    sort_func(data.copy())
+    end_time = time.perf_counter_ns()
+    return (end_time - start_time) / 10**6
+
+network_sizes = [1000, 5000, 10000, 50000]
+print("算法性能对比测试:")
+for size in network_sizes:
+    # 生成逆序数据,这是插入排序的最坏情况
+    worst_case_data = list(range(size, 0, -1))
+    
+    time_insertion = measure_performance(insertion_sort, worst_case_data)
+    time_merge = measure_performance(merge_sort, worst_case_data)
+    
+    print(f"--- 网络规模 n={size} (最坏情况) ---")
+    print(f"  - 插入排序: {time_insertion:.2f} ms")
+    print(f"  - 归并排序: {time_merge:.2f} ms")
+
+
分析与讨论
+

完成编程并得到输出后,请与右侧Agent讨论以下问题:

+
    +
  1. +

    性能验证:观察“交通大堵塞”(最坏情况)的测试结果,归并排序的性能表现与插入排序有何天壤之别?这是否验证了你在第一关的理论分析?

    +
  2. +
  3. +

    性能稳定性:如果我们将测试数据换成“畅通无阻”(最好情况)或“随机车流”(平均情况),你认为归并排序的运行时间会发生巨大变化吗?为什么?

    +
  4. +
  5. +

    空间成本:在实现 merge 函数时,你可能创建了一个新的数组 merged 来存放结果。这在算法分析中被称为“空间复杂度”。与在原数组上进行交换的插入排序相比,归并排序的这个特点是优点还是缺点?

    +
  6. +
  7. +

    最终决策:作为项目工程师,你会选择哪种排序算法用于我们的大规模交通调度系统?请综合考虑时间效率空间成本来陈述你的理由。

    +
  8. +
+ + + + \ No newline at end of file diff --git a/Html/apps/static/css/dashboard.css b/Html/apps/static/css/dashboard.css index becc690..9aad4c3 100644 --- a/Html/apps/static/css/dashboard.css +++ b/Html/apps/static/css/dashboard.css @@ -50,6 +50,7 @@ body { .dashboard { max-width: 1200px; margin: 0 auto; + padding: 0 20px; } .dashboard-title { @@ -63,9 +64,13 @@ body { /* 课程卡片容器 */ .course-cards { display: flex; - flex-wrap: wrap; + flex-wrap: nowrap; gap: 20px; - justify-content: center; + justify-content: flex-start; + padding: 10px 0; + overflow: hidden; + position: relative; + } /* 课程卡片 */ diff --git a/Html/apps/static/css/navbar.css b/Html/apps/static/css/navbar.css new file mode 100644 index 0000000..491d714 --- /dev/null +++ b/Html/apps/static/css/navbar.css @@ -0,0 +1,81 @@ +/* 页眉导航栏 基础样式 */ +.navbar { + display: flex; + justify-content: space-between; + align-items: center; + background-color: #ffffff; + padding: 10px 20px; + border-bottom: 1px solid #eee; + margin: 0; +} + +/* 导航栏 Logo 样式 */ +.navbar .logo h1 { + font-size: 20px; + font-weight: bold; + color: #1f2937; + margin: 0; +} + +/* 导航链接样式 */ +.navbar-links a { + color: #4b5563; + text-decoration: none; + margin: 0 15px; + font-size: 18px; + transition: color 0.3s; +} + +.navbar-links a:hover { + color: #2575fc; +} + +/* 头像容器样式 */ +.navbar .avatar { + margin-left: 0; +} + +.navbar .avatar img { + width: 32px; + height: 32px; + border-radius: 50%; + cursor: pointer; +} + +/* 下拉浮框 基础定位 */ +.dropdown { + position: relative; + display: inline-block; +} + +/* 下拉浮框 内容样式(默认隐藏) */ +.dropdown-content { + display: none; + position: absolute; + right: 0; + background-color: white; + min-width: 160px; + box-shadow: 0px 8px 16px rgba(0, 0, 0, 0.1); + border-radius: 6px; + z-index: 1; + padding: 8px 0; + font-size: 14px; +} + +/* 下拉浮框 链接样式 */ +.dropdown-content a { + color: #4b5563; + text-decoration: none; + padding: 8px 12px; + display: block; + transition: background-color 0.3s; +} + +.dropdown-content a:hover { + background-color: #f3f4f6; +} + +/* 下拉浮框 hover 显示 */ +.dropdown:hover .dropdown-content { + display: block; +} \ No newline at end of file diff --git a/Html/apps/templates/dashboard.html b/Html/apps/templates/dashboard.html index f56c1aa..76ba83b 100644 --- a/Html/apps/templates/dashboard.html +++ b/Html/apps/templates/dashboard.html @@ -9,20 +9,18 @@ {% include 'navbar.html' %} - -

—— 我的选课 ——

- + {% for course in user_selected_course %} -
+
课程封面

{{course.name}}

{{course.description}}

-
-
+
+
{% endfor %}
@@ -37,7 +35,7 @@

当前学习进度:


-

章节列表:

+

章节列表:

@@ -45,11 +43,11 @@