Skip to content

Commit 919ccc4

Browse files
committed
2021.02.03
1 parent 781ba59 commit 919ccc4

File tree

3 files changed

+169
-0
lines changed

3 files changed

+169
-0
lines changed

python/plat3/11014.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sys
2+
input = sys.stdin.readline
3+
T = int(input())
4+
d = [(-1,-1),(0,-1),(1,-1),(-1,1),(0,1),(1,1)]
5+
def dfs(idx):
6+
if visited[idx]:return False
7+
visited[idx]=True
8+
for nx in adj[idx]:
9+
if p[nx]==-1 or dfs(p[nx]):
10+
p[nx]=idx
11+
return True
12+
return False
13+
while T:
14+
T-=1
15+
N, M = map(int,input().split())
16+
arr = [list(input().strip()) for _ in range(N)]
17+
adj = [[] for _ in range(6401)]
18+
p = [-1]*6401
19+
total = 0
20+
for x in range(M):
21+
for y in range(N):
22+
if arr[y][x]=='x':continue
23+
total+=1
24+
if x%2:continue
25+
for dy,dx in d:
26+
ny,nx = y+dy,x+dx
27+
if 0<=ny<N and 0<=nx<M and arr[ny][nx]=='.':
28+
adj[y*80+x].append(ny*80+nx)
29+
ans = 0
30+
for i in range(6401):
31+
visited = [False]*6401
32+
if dfs(i):ans+=1
33+
print(total-ans)

python/plat3/2152.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import sys
2+
from collections import deque
3+
sys.setrecursionlimit(100000)
4+
input = sys.stdin.readline
5+
6+
N, M, S, T = map(int,input().split())
7+
adj = [[] for _ in range(N+1)]
8+
for i in range(M):
9+
s,t = map(int,input().split())
10+
adj[s].append(t)
11+
cnt,SN = 0,0
12+
dfsn = [0]*(N+1)
13+
scc_arr = []
14+
scc_num = [0]*(N+1)
15+
finished = [False]*(N+1)
16+
st = []
17+
18+
def scc(idx):
19+
global cnt,SN
20+
dfsn[idx] = cnt+1
21+
cnt+=1
22+
st.append(idx)
23+
result = dfsn[idx]
24+
for nx in adj[idx]:
25+
if dfsn[nx]==0:result = min(result,scc(nx))
26+
elif not finished[nx]: result = min(result, dfsn[nx])
27+
28+
if result == dfsn[idx]:
29+
curSCC = []
30+
while True:
31+
t = st.pop()
32+
curSCC.append(t)
33+
finished[t]=True
34+
scc_num[t]=SN
35+
if t==idx:break
36+
scc_arr.append(curSCC)
37+
SN+=1
38+
return result
39+
40+
for i in range(1,N+1):
41+
if dfsn[i]==0:scc(i)
42+
new_adj = [[] for _ in range(SN)]
43+
indgree = [0]*SN
44+
finished = [0]*SN
45+
new_s,new_t = scc_num[S],scc_num[T]
46+
for i,tmp in enumerate(scc_arr):
47+
for n in tmp:
48+
for nx in adj[n]:
49+
if scc_num[nx]==i:continue
50+
new_adj[i].append(scc_num[nx])
51+
indgree[scc_num[nx]]+=1
52+
def dfs():
53+
st = deque([new_s])
54+
can = [False]*SN
55+
can[new_s]=True
56+
finished[new_s]=len(scc_arr[new_s])
57+
q = deque([])
58+
for i in range(SN):
59+
if not indgree[i]: q.append(i)
60+
while q:
61+
n = q.popleft()
62+
for nx in new_adj[n]:
63+
if can[n]:
64+
finished[nx]=max(finished[nx],finished[n]+len(scc_arr[nx]))
65+
can[nx]=True
66+
indgree[nx]-=1
67+
if indgree[nx]==0:
68+
q.append(nx)
69+
return finished[new_t]
70+
print(dfs())

python/plat3/2912.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import sys
2+
import bisect
3+
input = sys.stdin.readline
4+
output = sys.stdout.write
5+
N, C = map(int,input().split())
6+
st = 1
7+
while st<N:
8+
st<<=1
9+
tree = [[] for _ in range(st<<1)]
10+
tmp = st
11+
flag = [-1]*(st<<1)
12+
for i,num in enumerate(list(map(int,input().split())),st):
13+
tree[i]=[num]
14+
flag[i]=num
15+
while tmp>1:
16+
ed = tmp
17+
tmp = tmp>>1
18+
for i in range(tmp,ed):
19+
l,r=0,0
20+
left,right = len(tree[i<<1]),len(tree[i<<1|1])
21+
while l<left or r<right:
22+
if r==right or (l<left and tree[i<<1][l]<tree[i<<1|1][r]):
23+
tree[i].append(tree[i<<1][l])
24+
l+=1
25+
else:
26+
tree[i].append(tree[i<<1|1][r])
27+
r+=1
28+
n = 0
29+
x = len(tree[i])/2
30+
for num in set(tree[i]):
31+
l = bisect.bisect_left(tree[i],num)
32+
r = bisect.bisect_right(tree[i],num)
33+
if r-l>x:
34+
flag[i]=num
35+
break
36+
def query(node,ns,ne,s,e):
37+
if ne<s or ns>e:return []
38+
if s<=ns and ne<=e:
39+
if flag[node]>0:
40+
return [flag[node]]
41+
return []
42+
mid = (ns+ne)>>1
43+
return query(node<<1,ns,mid,s,e)+query(node<<1|1,mid+1,ne,s,e)
44+
45+
def query2(node,ns,ne,s,e, num):
46+
if ne<s or ns>e:return 0
47+
if s<=ns and ne<=e:
48+
return bisect.bisect_right(tree[node],num)-bisect.bisect_left(tree[node],num)
49+
mid = (ns+ne)>>1
50+
return query2(node<<1,ns,mid,s,e,num)+query2(node<<1|1,mid+1,ne,s,e,num)
51+
52+
53+
M = int(input())
54+
55+
for i in range(M):
56+
a,b = map(int,input().split())
57+
p_list = query(1,1,st,a,b)
58+
total = b-a+1
59+
check = True
60+
for num in p_list:
61+
if query2(1,1,st,a,b,num)>total/2:
62+
output("yes %d\n"%num)
63+
check = False
64+
break
65+
if check:
66+
output("no\n")

0 commit comments

Comments
 (0)