how to

python-example

Feb 3, 2024
lifeusaco
1 Minutes
177 Words

ref: https://blog.csdn.net/m0_37966618/article/details/80374581

1
"""
2
ID: ***
3
LANG: PYTHON3
4
TASK: wormhole
5
"""
6
fin = open ('wormhole.in', 'r')
7
fout = open ('wormhole.out', 'w')
8
N = int(fin.readline())
9
total_List = list()
10
def checkPairings(listGenrt,crd):
11
for i in range(len(crd)):#assign starting point
12
sPt = crd[i]
13
lG = list(listGenrt)
14
org = list(sPt)
15
nXt = []
54 collapsed lines
16
num = 0
17
while(True):#checking solutions of this starting point
18
for tpl in listGenrt:
19
if sPt in tpl:
20
sPt = tpl[0 if tpl.index(sPt) == 1 else 1]
21
if tpl in lG:
22
lG.remove(tpl)
23
24
for x in crd:
25
if x[1] == sPt[1] and x != sPt and x[0] > sPt[0]:
26
if nXt==[] or (nXt!=[] and x[0] < nXt[0]):
27
nXt = x
28
29
if(nXt==[]):#can't find wh with the same Y value
30
break
31
sPt = list(nXt)
32
nXt = []
33
if sPt == org and len(lG)!=len(listGenrt):
34
num+=1
35
break
36
37
if num!=0:
38
total_List.append(listGenrt)
39
break
40
41
def createPairings(remaining):
42
if len(remaining)==0:
43
return
44
45
for x in range(1,len(remaining)):
46
if(x>1):
47
P2 = list(pairings)
48
#print("---{}".format(P2))
49
checkPairings(P2,crd)
50
51
del pairings[(len(P2)-int(len(remaining)/2)):len(P2)]
52
53
pairings.append((remaining[0], remaining[x]))
54
p = list(remaining)
55
p.pop(0)
56
p.pop(x-1)
57
createPairings(p)
58
if(x==len(remaining)-1 and len(pairings)==len(remaining)/2):
59
checkPairings(pairings,crd)
60
61
crd = list()
62
pairings = list()
63
for x in range(N):
64
c = list(map(int,fin.readline().split()))
65
crd.append(c)
66
#print(crd)
67
createPairings(crd)
68
fout.write("{}\n".format(str(len(total_List))))
69
fout.close()
Article title:python-example
Article author:Julyfun
Release time:Feb 3, 2024
Copyright 2025
Sitemap