-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedian.py
124 lines (100 loc) · 3.85 KB
/
median.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import sys
import math
testcase, num_of_values, total_questions = list(map(int,input().split()))
sys.stderr.write(str(testcase)+ str(num_of_values)+ str(total_questions)+'\n')
def find_min_and_max(candidate):
while len(candidate) > 2:
first = candidate.pop()
second = candidate.pop()
third = candidate.pop()
print(first, second, third)
candidate.add(first)
candidate.add(second)
candidate.add(third)
#print(first, second, third,file=sys.stderr)
value = input()
#print(int(value), file=sys.stderr)
candidate.remove(int(value))
#print(candidate, file=sys.stderr)
return candidate
def solve_case(num_of_values):
min_max_pairs = []
candidate_original = set()
for count in range(1,num_of_values+1):
candidate_original.add(count)
#print(candidate_original, file=sys.stderr)
candidate = candidate_original.copy()
for _ in range(int(num_of_values/2)):
candiate_temp = candidate.copy()
min_max = find_min_and_max(candiate_temp)
min_max_pairs.append(tuple(min_max))
#print(min_max, file=sys.stderr)
for val in min_max:
candidate.remove(val)
#print(_, file=sys.stderr)
#print(candidate, file=sys.stderr)
#print(min_max_pairs, file=sys.stderr)
answer = []
index = 0
for small, big in min_max_pairs:
#print(answer, file=sys.stderr)
#print(small, big, file=sys.stderr)
answer.insert(index,small)
answer.insert(len(answer)-index, big)
index += 1
#if int(value) == 1:
# pass
#else:
#iterate solution
print('answer: '+' '.join(str(item) for item in answer), file=sys.stderr)
def switchero(solution, a_position):
print(solution, file=sys.stderr)
b_position = len(solution)-a_position-1
temp = solution[a_position]
solution[a_position] = solution[b_position]
solution[b_position] = temp
print(solution, file=sys.stderr)
return solution
for index in range(0,int((len(answer)-2)/2)):
print(answer[index], answer[index+1], answer[index+2])
print(answer[index], answer[index+1], answer[index+2], file=sys.stderr)
value = input()
print('res: '+value, file=sys.stderr)
if int(value) == answer[index+1]:
print('pass', file=sys.stderr)
pass
else:
print('unoh!!!', file=sys.stderr)
answer = switchero(answer, index+1)
'''
switch_set = set()
for index in range(0,int((len(answer)-2)/4)):
index_c = (int(len(answer)/2)-1)-index
index_b = math.ceil(index_c/2)
print('sparta ',index, index_b, index_c, file=sys.stderr)
print(answer[index], answer[index_b], answer[index_c], file=sys.stderr)
if(index < index_b <index_c):
print(answer[index], answer[index_b], answer[index_c])
value = input()
print('res: '+value, file=sys.stderr)
if int(value) == answer[index_b]:
print('pass', file=sys.stderr)
pass
else:
print('unoh!!!', file=sys.stderr)
if index_b in switch_set:
print('switch '+str(index_c), file=sys.stderr)
answer = switchero(answer, index_c)
switch_set.add(index_c)
else:
print('switch '+str(index_c), file=sys.stderr)
answer = switchero(answer, index_c)
switch_set.add(index_c)
'''
print(' '.join(str(item) for item in answer), file=sys.stderr)
print(' '.join(str(item) for item in answer))
value = input()
print('judge says '+value, file=sys.stderr)
for i in range(testcase):
print('case '+str(i), file=sys.stderr)
solve_case(num_of_values)