hello-barcelona-17/day4/8_int.py

67 lines
1.4 KiB
Python

from random import randint
from sys import stdin, stderr, stdout
BOUND = 10**6
#BOUND = 5
pts = []
while len(pts) < 100:
x = randint(-BOUND, BOUND)
y = randint(-BOUND, BOUND)
if (x, y) in pts:
continue
pts.append((x, y))
print(len(pts))
stdout.flush()
nbQuestions = 0
def question(l):
global nbQuestions
x, y = [int(x) for x in l.strip().split()]
nbQuestions += 1
out = 0
for (xi, yi) in pts:
if xi <= x and yi <= y:
out += 1
return out
def check(l):
global nbQuestions
gPts = set()
print("{} questions, {} allowed".format(
nbQuestions,
50 * len(pts)), file=stderr)
for pt in l:
gPts.add(pt)
if len(gPts) != len(pts):
print('Fail', file=stderr)
return
for pt in gPts:
if pt not in pts:
print('Fail (not in)', file=stderr)
return
print('Success', file=stderr)
while True:
line = input()
if line[0] == '!':
spl = line[2:].strip().split()
l = []
for i in range(0, len(spl)//2):
l.append((int(spl[2*i]), int(spl[2*i+1])))
check(l)
print(l, file=stderr)
print(pts, file=stderr)
break
elif line[0] == '?':
print(question(line[2:]))
stdout.flush()
elif line[0] == '*':
print(line[1:], file=stderr)
else:
print("OMG", file=stderr)