Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import sys
- def solveInternal(n, b, askFunc):
- questions = [0] * n
- responses = [0] * (n - b)
- for step in [1, 2, 4, 8, 16]:
- q = []
- while len(q) < n:
- for delta in xrange(step):
- q.append(0)
- for delta in xrange(step):
- q.append(1)
- q = q[:n]
- assert len(q) == n
- r = askFunc(q)
- assert len(r) == n - b
- for i in xrange(n):
- questions[i] |= q[i] * step
- for i in xrange(n - b):
- responses[i] |= r[i] * step
- result = []
- i = 0
- for r in responses:
- while i < n and questions[i] != r:
- result.append(i)
- i += 1
- i += 1
- while i < n:
- result.append(i)
- i += 1
- return result
- def solve():
- def askIO(a):
- s = "".join(map(str, a))
- print s
- sys.stdout.flush()
- return [int(x) for x in raw_input()]
- T = int(raw_input())
- for t in xrange(T):
- n, b, f = map(int, raw_input().split())
- res = solveInternal(n, b, askIO)
- print " ".join(map(str, res))
- sys.stdout.flush()
- response = int(raw_input())
- if response == -1:
- return
- def stress():
- random.seed(322)
- for test in xrange(1000):
- n = 1000
- b = 15
- s = set()
- while len(s) < b:
- s.add(random.randint(0, n - 1))
- ss = sorted(s)
- def askEmulator(a):
- assert len(a) == n
- response = []
- for i in xrange(n):
- if i not in s:
- response.append(a[i])
- return response
- print "TESTING:", n, b, ss
- res = solveInternal(n, b, askEmulator)
- if res != ss:
- print "FAILED:", n, b, ss, "=>", res
- raise Exception()
- else:
- print "PASSED:", n, b, ss, "=>", res
- print "OK!"
- def main():
- # stress()
- solve()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement