add 练习题.

This commit is contained in:
Licsber 2022-04-09 01:07:54 +08:00
parent 2cb75e7bbc
commit 7b77a1216e
13 changed files with 200 additions and 0 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

8
.idea/Algorithm.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Algorithm.iml" filepath="$PROJECT_DIR$/.idea/Algorithm.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

0
lanqiao/__init__.py Normal file
View File

4
lanqiao/main.py Normal file
View File

@ -0,0 +1,4 @@
import io
import sys
sys.stdin = io.StringIO('lanqiao')

View File

@ -0,0 +1,55 @@
map_in = [
['A', 'E', 1],
['A', 'B', 2],
['A', 'C', 1],
['A', 'D', 1],
['A', 'E', 1],
['B', 'G', 1],
['B', 'J', 2],
['C', 'D', 3],
['C', 'G', 3],
['C', 'F', 3],
['D', 'G', 2],
['D', 'H', 1],
['D', 'I', 2],
['E', 'H', 1],
['E', 'I', 3],
['F', 'J', 1],
['F', 'G', 1],
['G', 'K', 2],
['G', 'I', 3],
['H', 'L', 2],
['H', 'I', 1],
['I', 'M', 3],
['J', 'S', 2],
['K', 'N', 1],
['K', 'L', 3],
['L', 'R', 1],
['L', 'M', 1],
['M', 'N', 2],
['M', 'Q', 1],
['M', 'S', 1],
['N', 'P', 1],
['Q', 'O', 1],
['O', 'R', 3],
['P', 'O', 1],
['R', 'S', 1],
]
def dp(now_dis, next_node):
for src, dst, dis in map_in:
if src == next_node:
now_dis += dis
if dst == 'S':
ans.append(now_dis)
else:
dp(now_dis, dst)
ans = []
for src, dst, dis in map_in:
if src == 'A':
dp(dis, dst)
print(min(ans))

View File

@ -0,0 +1,59 @@
map_in = [
['A', 'E', 1],
['A', 'B', 2],
['A', 'C', 1],
['A', 'D', 1],
['A', 'E', 1],
['B', 'G', 1],
['B', 'J', 2],
['C', 'D', 3],
['C', 'G', 3],
['C', 'F', 3],
['D', 'G', 2],
['D', 'H', 1],
['D', 'I', 2],
['E', 'H', 1],
['E', 'I', 3],
['F', 'J', 1],
['F', 'G', 1],
['G', 'K', 2],
['G', 'I', 3],
['H', 'L', 2],
['H', 'I', 1],
['I', 'M', 3],
['J', 'S', 2],
['K', 'N', 1],
['K', 'L', 3],
['L', 'R', 1],
['L', 'M', 1],
['M', 'N', 2],
['M', 'Q', 1],
['M', 'S', 1],
['N', 'P', 1],
['Q', 'O', 1],
['O', 'R', 3],
['P', 'O', 1],
['R', 'S', 1],
]
# 点的数量 数出来的
n = 19
# 初始化图 到自身到距离为0
fig = [[float('inf')] * n for _ in range(n)]
for i in range(n):
fig[i][i] = 0
# 构建好路 每个节点之间的距离
for src, dst, dis in map_in:
src, dst = ord(src) - ord('A'), ord(dst) - ord('A')
fig[src][dst] = fig[dst][src] = dis
# 从起点到每个节点到距离 S为最后一个节点 因为是字母序排序的
dis = [float('inf')] * n
dis[0] = 0
for i in range(n):
for j in range(n):
dis[j] = min(dis[j], dis[i] + fig[i][j])
print(dis)
print(dis[-1])

View File

@ -0,0 +1,18 @@
import io
import sys
sys.stdin = io.StringIO('lanqiao')
s_in = input()
counter = [0] * 26
count_max = 0
for ch in s_in:
idx = ord(ch) - ord('a')
counter[idx] += 1
count_max = max(count_max, counter[idx])
for i in range(26):
if count_max == counter[i]:
print(chr(i + ord('a')))
print(count_max)
break

View File

@ -0,0 +1,24 @@
import io
import sys
sys.stdin = io.StringIO('20200202')
import datetime
s_in = input()
year, month, day = int(s_in[:4]), int(s_in[4:6]), int(s_in[-2:])
now = datetime.date(year, month, day)
one_day = datetime.timedelta(days=1)
reverse = True
while True:
now += one_day
s = str(now).replace('-', '')
if reverse and s[::] == s[::-1]:
print(s)
reverse = False
# ABABBABA
if s[0] == s[2] == s[5] == s[7] and s[1] == s[3] == s[4] == s[6]:
print(s)
break

0
lanqiao/test/__init__.py Normal file
View File