Skip to content

Commit ef9ef41

Browse files
authored
Twisty Little Passages
1 parent cbb4871 commit ef9ef41

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

TwistyLittlePassages.py3

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
def walk():
2+
print("W", flush=True)
3+
return list(map(int, input().split()))
4+
5+
def teleport(i):
6+
print("T %s" % i, flush=True)
7+
return list(map(int, input().split()))
8+
9+
def estimate(i):
10+
print("E %s" % i, flush=True)
11+
12+
def twisty_little_passages():
13+
N, K = list(map(int, input().split()))
14+
R, P = list(map(int, input().split()))
15+
candidates = {i for i in range(1, N+1) if i != R}
16+
degree = degree_T = P
17+
cnt_T = 1
18+
for i in range(K):
19+
if not candidates:
20+
break
21+
if i%2 == 0:
22+
R, P = walk()
23+
else:
24+
R, P = teleport(next(iter(candidates)))
25+
degree_T += P
26+
cnt_T += 1
27+
if R in candidates:
28+
candidates.remove(R)
29+
degree += P
30+
avg = degree_T/cnt_T
31+
estimate(int((degree+avg*len(candidates))/2))
32+
33+
for case in range(int(input())):
34+
twisty_little_passages()

0 commit comments

Comments
 (0)