add 电信研发工程师考试内容.
This commit is contained in:
parent
2aa12fbb6e
commit
6b40f708b2
@ -1,8 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (Algorithm)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -1,5 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="PROJECT_PROFILE" value="Default" />
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
|
@ -1,4 +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" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (Algorithm)" project-jdk-type="Python SDK" />
|
||||
</project>
|
0
ct/__init__.py
Normal file
0
ct/__init__.py
Normal file
17
ct/l1/8-平衡数.py
Normal file
17
ct/l1/8-平衡数.py
Normal file
@ -0,0 +1,17 @@
|
||||
def f(x):
|
||||
y = 1
|
||||
for j in x:
|
||||
y *= int(j)
|
||||
return y
|
||||
|
||||
|
||||
n = input()
|
||||
flag = True
|
||||
for i in range(1, len(n)):
|
||||
left, right = n[:i], n[i:]
|
||||
if f(left) == f(right):
|
||||
flag = False
|
||||
print("YES")
|
||||
break
|
||||
if flag:
|
||||
print("No")
|
15
ct/l2/14-Ruby和薯条.py
Normal file
15
ct/l2/14-Ruby和薯条.py
Normal file
@ -0,0 +1,15 @@
|
||||
import io
|
||||
import sys
|
||||
|
||||
sys.stdin = io.StringIO('''5 2 3
|
||||
3 1 6 2 5''') # 4
|
||||
|
||||
n, l, r = map(int, input().split())
|
||||
a = list(map(int, input().split()))
|
||||
s = 0
|
||||
for i in range(n - 1):
|
||||
for j in range(i + 1, n):
|
||||
if l <= abs(a[i] - a[j]) <= r:
|
||||
s += 1
|
||||
|
||||
print(s)
|
19
ct/l2/15-小红无敌.py
Normal file
19
ct/l2/15-小红无敌.py
Normal file
@ -0,0 +1,19 @@
|
||||
import io
|
||||
import sys
|
||||
|
||||
sys.stdin = io.StringIO('''2 3 1 3''') # 26
|
||||
|
||||
a, h, b, k = map(int, input().split())
|
||||
c = 0
|
||||
while h > 0 and k > 0:
|
||||
c += a
|
||||
c += b
|
||||
h -= b
|
||||
k -= a
|
||||
|
||||
if h > 0 > k:
|
||||
c += a * 10
|
||||
elif h <= 0 < k:
|
||||
c += b * 10
|
||||
|
||||
print(c)
|
22
ct/l2/16-优美字符串.py
Normal file
22
ct/l2/16-优美字符串.py
Normal file
@ -0,0 +1,22 @@
|
||||
import io
|
||||
import sys
|
||||
|
||||
sys.stdin = io.StringIO('''4
|
||||
a
|
||||
ab
|
||||
abbc
|
||||
aaabb''') # 1 2 5 8
|
||||
|
||||
t = int(input())
|
||||
s = []
|
||||
for _ in range(t):
|
||||
s.append(input())
|
||||
|
||||
for i in s:
|
||||
k = 0
|
||||
for j in range(len(i)):
|
||||
if j + 1 < len(i):
|
||||
if i[j] == i[j + 1]:
|
||||
k += 1
|
||||
|
||||
print(k + len(i))
|
33
ct/l2/17-重排字符串.py
Normal file
33
ct/l2/17-重排字符串.py
Normal file
@ -0,0 +1,33 @@
|
||||
import io
|
||||
import sys
|
||||
|
||||
sys.stdin = io.StringIO('''1
|
||||
aabbccc''') # cabcacb
|
||||
|
||||
from collections import Counter
|
||||
|
||||
|
||||
def reorganizeString(str):
|
||||
cnt = Counter(str)
|
||||
# 桶的数目等于字符串中最多的元素的数目
|
||||
bucketNum = cnt.most_common(1)[0][1]
|
||||
buckets = [[] for _ in range(bucketNum)]
|
||||
idx = 0
|
||||
# 优先填充数目最多的元素
|
||||
for c, num in cnt.most_common():
|
||||
while num:
|
||||
buckets[idx].append(c)
|
||||
# 循环在不同桶中进行填充
|
||||
idx = (idx + 1) % bucketNum
|
||||
num -= 1
|
||||
return "".join(["".join(bucket) for bucket in buckets]) if list(map(len, buckets)).count(1) <= 1 else ""
|
||||
|
||||
|
||||
n = int(input())
|
||||
str = input()
|
||||
result = reorganizeString(str)
|
||||
if result == '':
|
||||
print('no')
|
||||
else:
|
||||
print('yes')
|
||||
print(result)
|
22
ct/l2/18-指定值倍数取数.py
Normal file
22
ct/l2/18-指定值倍数取数.py
Normal file
@ -0,0 +1,22 @@
|
||||
import io
|
||||
import sys
|
||||
|
||||
sys.stdin = io.StringIO('''5 5
|
||||
4 8 2 9 1''') # 20
|
||||
|
||||
n, k = map(int, input().split())
|
||||
a = list(map(int, input().split()))
|
||||
dp = [[-1] * k for i in range(n + 1)]
|
||||
dp[0][0] = 0
|
||||
for i in range(n + 1):
|
||||
for j in range(k):
|
||||
if dp[i - 1][j] != -1:
|
||||
dp[i][j] = dp[i - 1][j]
|
||||
tmp = (j - a[i - 1] % k + k) % k
|
||||
if dp[i - 1][tmp] != -1:
|
||||
dp[i][j] = max(dp[i][j], dp[i - 1][tmp] + a[i - 1])
|
||||
|
||||
if dp[n][0] == 0:
|
||||
print(-1)
|
||||
else:
|
||||
print(dp[n][0])
|
16
ct/l2/19-寻找公倍数和公约数.py
Normal file
16
ct/l2/19-寻找公倍数和公约数.py
Normal file
@ -0,0 +1,16 @@
|
||||
import io
|
||||
import sys
|
||||
|
||||
sys.stdin = io.StringIO('''2 60 3 96''') # 12 / 6
|
||||
|
||||
a = list(map(int, input().split()))
|
||||
_min, _max = min(a), max(a)
|
||||
k = 0
|
||||
for i in range(_min, _max):
|
||||
if i % a[0] + i % a[2] + a[1] % i + a[3] % i == 0:
|
||||
k += 1
|
||||
print(i)
|
||||
break
|
||||
|
||||
if k == 0:
|
||||
print(-1)
|
27
ct/l2/20-Ranko的手表.py
Normal file
27
ct/l2/20-Ranko的手表.py
Normal file
@ -0,0 +1,27 @@
|
||||
import io
|
||||
import sys
|
||||
|
||||
sys.stdin = io.StringIO('''18:0?
|
||||
2?:1?''') # 121 319
|
||||
|
||||
|
||||
def check(tStr, tInt):
|
||||
s = '%02d' % (tInt / 60) + ':' + '%02d' % (tInt % 60)
|
||||
for x in range(len(s)):
|
||||
if tStr[x] != '?' and tStr[x] != s[x]:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
tStr1 = input()
|
||||
tStr2 = input()
|
||||
minT, maxT = 9999, 0
|
||||
for i in range(0, 24 * 60):
|
||||
if check(tStr1, i):
|
||||
for j in range(i + 1, 24 * 60):
|
||||
if check(tStr2, j):
|
||||
minT = j - i if 0 < j - i < minT else minT
|
||||
maxT = j - i if maxT < j - i else maxT
|
||||
|
||||
print(minT, maxT)
|
13
ct/l2/3-动态规划-不相邻取数.py
Normal file
13
ct/l2/3-动态规划-不相邻取数.py
Normal file
@ -0,0 +1,13 @@
|
||||
import io
|
||||
import sys
|
||||
|
||||
sys.stdin = io.StringIO('''4
|
||||
2 6 4 1''') # 7
|
||||
|
||||
n = int(input())
|
||||
a = list(map(int, input().split()))
|
||||
dp0, dp1 = 0, a[0]
|
||||
for i in range(1, n):
|
||||
dp0, dp1 = dp1, max(dp1, dp0 + a[i])
|
||||
|
||||
print(dp1)
|
0
ct/l2/__init__.py
Normal file
0
ct/l2/__init__.py
Normal file
13
ct/l2/两数乘积k.py
Normal file
13
ct/l2/两数乘积k.py
Normal file
@ -0,0 +1,13 @@
|
||||
from bisect import *
|
||||
|
||||
n, k = map(int, input().split())
|
||||
a = sorted(list(map(int, input().split())))
|
||||
pair = [0, 0, 0]
|
||||
for idx in range(n - 1):
|
||||
l = bisect_left(a, k / a[idx], idx + 1, n)
|
||||
r = bisect_right(a, k / a[idx], idx + 1, n)
|
||||
pair[0] += n - r
|
||||
pair[1] += r - l
|
||||
pair[2] += l - idx - 1
|
||||
|
||||
print(*pair)
|
12
ct/l2/回文.py
Normal file
12
ct/l2/回文.py
Normal file
@ -0,0 +1,12 @@
|
||||
def solution(s):
|
||||
length = len(s)
|
||||
for n in range(2, length + 1):
|
||||
for i in range(0, length - n + 1):
|
||||
if s[i:i + n - 1] == s[i + n - 1:i:-1]:
|
||||
print(n)
|
||||
return
|
||||
print("-1")
|
||||
|
||||
|
||||
s = input()
|
||||
solution(s)
|
44
ct/l2/打家劫舍3.py
Normal file
44
ct/l2/打家劫舍3.py
Normal file
@ -0,0 +1,44 @@
|
||||
import sys
|
||||
|
||||
sys.setrecursionlimit(100010) # 修改默认递归深度
|
||||
|
||||
|
||||
class BiTNode(object): # 二叉树节点
|
||||
def __init__(self, data):
|
||||
self.data = data
|
||||
self.dp = [0, 0] # dp[0]表示不偷该节点,dp[1]表示偷该节点
|
||||
self.lChild = None
|
||||
self.rChild = None
|
||||
|
||||
|
||||
# 二叉树的后序遍历
|
||||
def dfs(T):
|
||||
if T != None:
|
||||
dfs(T.lChild)
|
||||
dfs(T.rChild)
|
||||
lChildDp = [0, 0]
|
||||
rChildDp = [0, 0]
|
||||
if T.lChild != None:
|
||||
lChildDp = T.lChild.dp
|
||||
if T.rChild != None:
|
||||
rChildDp = T.rChild.dp
|
||||
# 不偷该节点,左节点的最优情况(偷与不偷取大者) + 右节点的最优情况(偷与不偷取大者)
|
||||
T.dp[0] = max(lChildDp[0], lChildDp[1]) + max(rChildDp[0], rChildDp[1])
|
||||
# 偷该节点,该节点的现金 + 不偷左节点获得的现金 + 不偷右节点获得的现金
|
||||
T.dp[1] = T.data + lChildDp[0] + rChildDp[0]
|
||||
|
||||
|
||||
n = int(input())
|
||||
nodes = list(map(int, input().split()))
|
||||
fathers = list(map(int, input().split()))
|
||||
nodeArray = [BiTNode(None) for i in range(n)]
|
||||
for i in range(n): # 构造二叉树
|
||||
nodeArray[i].data = nodes[i]
|
||||
f = fathers[i] - 1 # 节点编号从0开始
|
||||
if f >= 0:
|
||||
if nodeArray[f].lChild == None:
|
||||
nodeArray[f].lChild = nodeArray[i]
|
||||
else:
|
||||
nodeArray[f].rChild = nodeArray[i]
|
||||
dfs(nodeArray[0]) # 二叉树的后序遍历,nodeArray[0]为根节点
|
||||
print(max(nodeArray[0].dp[0], nodeArray[0].dp[1]))
|
0
ct/main.py
Normal file
0
ct/main.py
Normal file
21
luogu/P1216/main.py
Normal file
21
luogu/P1216/main.py
Normal file
@ -0,0 +1,21 @@
|
||||
import io
|
||||
import sys
|
||||
|
||||
sys.stdin = io.StringIO('''5
|
||||
7
|
||||
3 8
|
||||
8 1 0
|
||||
2 7 4 4
|
||||
4 5 2 6 5''')
|
||||
|
||||
n = int(input())
|
||||
nums = []
|
||||
for i in range(n):
|
||||
nums.append(list(map(int, input().split())))
|
||||
|
||||
f = [[0] * (n + 1) for _ in range(n + 1)]
|
||||
for i in range(n - 1, -1, -1):
|
||||
for j in range(i + 1):
|
||||
f[i][j] = max(f[i + 1][j], f[i + 1][j + 1]) + nums[i][j]
|
||||
|
||||
print(f[0][0])
|
0
luogu/__init__.py
Normal file
0
luogu/__init__.py
Normal file
Loading…
Reference in New Issue
Block a user