Compare commits

..

6 Commits

Author SHA1 Message Date
f014389281 add 堆排序. 2024-05-15 16:16:05 +08:00
94021b3455 doc 格式化问题. 2023-07-08 15:12:02 +08:00
4d1c595a6b add 处理输入后ac. 2023-07-08 15:08:10 +08:00
f674b758aa add tle. 2023-07-08 14:01:55 +08:00
ab7ad7c09e add 数论基础 唯一分解定理(算术基本定理). 2023-07-08 13:22:56 +08:00
7d65b8c204 add 简单判断签到题. 2023-07-08 13:02:23 +08:00
9 changed files with 134 additions and 2 deletions

3
.idea/Algorithm.iml generated
View File

@@ -2,9 +2,10 @@
<module type="PYTHON_MODULE" version="4"> <module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
<excludeFolder url="file://$MODULE_DIR$/venv" /> <excludeFolder url="file://$MODULE_DIR$/venv" />
</content> </content>
<orderEntry type="jdk" jdkName="Python 3.10 (Algorithm)" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Python 3.12 (Algorithm)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

5
.idea/misc.xml generated
View File

@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (Algorithm)" project-jdk-type="Python SDK" /> <component name="Black">
<option name="sdkName" value="Python 3.12 (Algorithm)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (Algorithm)" project-jdk-type="Python SDK" />
</project> </project>

0
learn_sort/__init__.py Normal file
View File

31
learn_sort/heap.py Normal file
View File

@@ -0,0 +1,31 @@
def heapify(nums, start, end):
parent = start
son = parent * 2 + 1
while son <= end:
if son + 1 <= end and nums[son] < nums[son + 1]:
son += 1
if nums[parent] > nums[son]:
return
else:
nums[parent], nums[son] = nums[son], nums[parent]
parent = son
son = parent * 2 + 1
def heap_sort(nums):
n = len(nums)
for i in range(n // 2 - 1, -1, -1):
heapify(nums, i, n - 1)
print(nums)
for i in range(n - 1, 0, -1):
nums[0], nums[i] = nums[i], nums[0]
heapify(nums, 0, i - 1)
print(nums)
if __name__ == '__main__':
# https://leetcode.cn/problems/sort-an-array/description/
_nums = [7, 10, 13, 15, 4, 20, 19, 8]
heap_sort(_nums)
print(_nums)

View File

@@ -0,0 +1,2 @@
if __name__ == '__main__':
pass

View File

@@ -0,0 +1,29 @@
import io
import sys
sys.stdin = io.StringIO('''5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3''')
def fun(a, b, c, n):
total = a + b + c + n
if total % 3 != 0:
return False
avg = total // 3
if avg - a < 0 or avg - b < 0 or avg - c < 0:
return False
return True
t = int(input())
for _ in range(t):
print('YES' if fun(*map(int, input().split())) else 'NO')
if __name__ == '__main__':
pass

View File

@@ -0,0 +1,25 @@
import io
import sys
sys.stdin = io.StringIO('''4
100 98
42 32
1000000000000000000 1
41 40''')
# 数论基础 唯一分解定理(算术基本定理)
# x - n*p = y
# 则 n*p = x - y = z
# 大于1的整数就满足 可分解为任意素数乘积
def fun(x, y):
z = x - y
return z > 1
t = int(input())
for _ in range(t):
print('YES' if fun(*map(int, input().split())) else 'NO')
if __name__ == '__main__':
pass

View File

@@ -0,0 +1,41 @@
import io
import sys
sys.stdin = io.StringIO('''3
6
4 5 1 3 2 6
5
5 3 1 2 4
4
1 4 3 2''')
def fun(n, loc):
ans = [0] * n
ans[0] = 1
l, r = loc[1], loc[1]
for i in range(2, n + 1):
l = min(l, loc[i])
r = max(r, loc[i])
if r - l + 1 == i:
ans[i - 1] = 1
print(''.join(map(str, ans)))
t = int(input())
for _ in range(t):
n = int(input())
p = []
loc = [0] * (n + 1)
nums = input().split()
for i in range(n):
num = int(nums[i])
p.append(num)
loc[num] = i
fun(n, loc)
if __name__ == '__main__':
pass

View File