Compare commits

..

No commits in common. "fe1a61e3695d9e50038aa794b46837531caa1617" and "2aa12fbb6e37b00a54fd61417a7bdb3e45bc8cb1" have entirely different histories.

23 changed files with 3 additions and 332 deletions

View File

@ -1,10 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<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" /> <orderEntry type="inheritedJdk" />
</content>
<orderEntry type="jdk" jdkName="Python 3.10 (Algorithm)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

View File

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

View File

@ -1,4 +1,4 @@
<?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="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project> </project>

View File

View File

@ -1,17 +0,0 @@
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")

View File

@ -1,24 +0,0 @@
import io
import sys
sys.stdin = io.StringIO('''4
5 5 5
1 2 40
10 5 41
7 2 42''')
# 80%
n = int(input())
flag = True
for _ in range(n):
chang, kuan, gao = map(int, input().split())
if gao >= 41:
continue
tiji = chang * kuan * gao
flag = False
print(tiji)
if flag:
print(0)

View File

@ -1,19 +0,0 @@
import io
import sys
sys.stdin = io.StringIO('''2
10
20''')
from math import pi, e, log10, ceil
m = int(input())
for _ in range(m):
num = int(input())
if num == 0 or num == 1:
print(1)
continue
digit = ceil(log10(float(2 * pi * num)) / 2 + num * log10(float(num / e)))
print(digit)

View File

@ -1,15 +0,0 @@
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)

View File

@ -1,19 +0,0 @@
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)

View File

@ -1,22 +0,0 @@
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))

View File

@ -1,33 +0,0 @@
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)

View File

@ -1,22 +0,0 @@
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])

View File

@ -1,16 +0,0 @@
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)

View File

@ -1,27 +0,0 @@
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)

View File

@ -1,13 +0,0 @@
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)

View File

View File

@ -1,13 +0,0 @@
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)

View File

@ -1,12 +0,0 @@
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)

View File

@ -1,44 +0,0 @@
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]))

View File

View File

@ -1,21 +0,0 @@
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])

View File

View File

@ -1,9 +0,0 @@
import io
import sys
sys.stdin = io.StringIO('''5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5''')