# 5906. 句子中的有效单词数

return sum(bool(re.match(r'[a-z]*([a-z]-[a-z]+)?[!.,]?\$', w)) for w in sc.split())

class Solution:
def countValidWords(self, sentence: str) -> int:
nums=[str(i) for i in range(10)]
def func(x):
n=len(x)
if x.count('-')>=2:return False
if x.count('!')>=2:return False
if x.count('.')>=2:return False
if x.count(',')>=2:return False
flag1,flag2,flag3=False,False,False
for idx,val in enumerate(x):
if val.isalpha():
flag1=True
if flag2:
flag3=True
if val=='-':
flag2=True
if not flag1:
return False

if val in ('!','.', ',') and idx!=n-1:
return False
if val in nums:
return False
if flag2 and not flag3:return False
return True

res=0
for x in sentence.split():
if func(x):
print(x)
res+=1
return res


# 5907. 下一个更大的数值平衡数

• 0

<

=

n

<

=

1

0

6

0 <= n <= 10^6

，n实际上可以取到999999

class Solution:
def nextBeautifulNumber(self, n: int) -> int:
def func(x):
s=set(x)
for k in s:
if x.count(k)!=int(k):
return False
return True
res={1,22,122,212,221,333,1333,3133,3313,3331,4444,55555,666666,1224444}
seq1='22333'
seq2='14444'
for x in permutations(seq1, 5):
tmp=''.join(x)
for x in permutations(seq2, 5):
tmp=''.join(x)

seq3='122333'
seq4='224444'
seq5='155555'
for x in permutations(seq3,6):
tmp=''.join(x)
for x in permutations(seq4, 6):
tmp=''.join(x)
for x in permutations(seq5, 6):
tmp=''.join(x)

res=sorted(list(res))
idx=bisect.bisect_left(res,n)
if res[idx]==n:
return res[idx+1]
else:
return res[idx]


# 5908. 统计最高分的节点数目

dfs轻松搞定，不过建树的过程值得注意

class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None

class Solution:
def countHighestScoreNodes(self, parents: List[int]) -> int:
n=len(parents)
tree=[TreeNode(i) for i in range(n)]

for i in range(1,n):
a,b=tree[i],tree[parents[i]]
if not b.left:
b.left=a
else:
b.right=a

nums=[None]*n
def dfs(root):
if not root:return 0
l,r=0,0
if root.left:l+=1
if root.right:r+=1
l+=dfs(root.left)
r+=dfs(root.right)
nums[root.val]=(l,r)
return l+r

dfs(tree[0])
res=[0]*n
for i in range(n):
a,b=nums[i][0],nums[i][1]
c=n-a-b-1
if a==0:a=1
if b==0:b=1
if c==0:c=1
res[i]=a*b*c
# print(res)
return res.count(max(res))


# 5909. 并行课程 III

class Solution:
def minimumTime(self, n: int, relations: List[List[int]], time: List[int]) -> int:
p = collections.defaultdict(list)
for pc, c in relations: p[c].append(pc)
@cache
def get_res(c): return time[c - 1] + max([0] + [get_res(pc) for pc in p[c]])
return max(get_res(c) for c in range(1, n + 1))


# 轻松一刻

from time import sleep

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get('https://www.arealme.com/reaction-test/cn/')
wait=WebDriverWait(driver,10)
start=wait.until(EC.presence_of_element_located((By.XPATH,'//button[@class="progress-button pure-button pure-button-primary"]')))
start.click()

sleep(3)
ActionChains(driver).move_by_offset(200, 100).click().perform()

for _ in range(5):
green=wait.until(EC.presence_of_element_located((By.XPATH,'//div[@class="tfny-circleGreen"]')))
green.click()

# res=wait.until(EC.presence_of_element_located((By.XPATH,'//div[@id="reactNumber"]')))
# print(res.text)



THE END

)">