Skip to content

Commit 0217508

Browse files
committed
Deployed 1b7a3f8 with MkDocs version: 1.0.4
1 parent 12c6868 commit 0217508

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

19_python内置常用算法和数据结构/builtins/index.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@
194194
<li class="toctree-l2"><a href="#python_1">python 交换列表元素的坑</a></li>
195195

196196

197+
<li class="toctree-l2"><a href="#_4">兼容提交格式</a></li>
198+
199+
197200
</ul>
198201
</li>
199202

@@ -636,6 +639,51 @@ <h1 id="python_1">python 交换列表元素的坑</h1>
636639

637640
return n+1
638641
</code></pre>
642+
<h1 id="_4">兼容提交格式</h1>
643+
<p>注意牛客网有两种模式,一种是和 leetcode 一样的提交(无需处理输入),只需要提交核心代码。
644+
一种是 ACM 模式,还需要自己处理输入和输出。
645+
建议使用这种兼容写法,同样的题目可以同时提交到 牛客和leetcode。
646+
这道题目为例子 [679] 奖品分配 https://www.acwing.com/problem/content/681/</p>
647+
<pre><code class="language-py"># 这段代码可以直接以OJ输入模式提交,如果题目一样,直接复制 Solution 类就可以同时提交到leetcode
648+
class Solution:
649+
def solve(self, scores):
650+
&quot;&quot;&quot;
651+
思路:记忆化搜索。时间O(N)
652+
对于旁边都比自己大的点,它肯定是1
653+
对于旁边有比自己小的点,先算出比自己小的点的值再+1就好了。
654+
每个点如果计算过了就记忆化,下次再计算他的时候不用重复递归直接返回。
655+
参考:https://www.acwing.com/solution/acwing/content/1520/
656+
&quot;&quot;&quot;
657+
from functools import lru_cache
658+
n = len(scores)
659+
660+
@lru_cache(maxsize=None)
661+
def dfs(x):
662+
left = (x-1+n) % n
663+
right = (x+1) % n
664+
665+
if scores[x] &lt;= scores[left] and scores[x] &lt;= scores[right]: # 注意是 &lt;= ,下边是 &lt;
666+
return 1
667+
668+
l, r = 0, 0
669+
if scores[left] &lt; scores[x]:
670+
l = dfs(left)
671+
if scores[right] &lt; scores[x]:
672+
r = dfs(right)
673+
674+
return max(l, r) + 1
675+
676+
return sum([dfs(i) for i in range(n)])
677+
678+
679+
if __name__ == &quot;__main__&quot;: # python3 提交,python3 input 都当做 str 输入
680+
so = Solution() # 构造 Solution 实例后续调用
681+
n = int(input())
682+
for i in range(n):
683+
arrlen = input()
684+
arr = list(map(int, input().split()))
685+
print(so.solve(arr))
686+
</code></pre>
639687

640688
</div>
641689
</div>

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,5 +599,5 @@ <h2 id="_22">本电子书制作和写作方式</h2>
599599

600600
<!--
601601
MkDocs version : 1.0.4
602-
Build Date UTC : 2022-02-19 02:41:07
602+
Build Date UTC : 2022-02-19 03:29:49
603603
-->

search/search_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

sitemap.xml.gz

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)