Skip to content

Instantly share code, notes, and snippets.

@Patlatus
Created April 8, 2018 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Patlatus/a4353dd67e49d235745aeb83b9e1d66e to your computer and use it in GitHub Desktop.
Save Patlatus/a4353dd67e49d235745aeb83b9e1d66e to your computer and use it in GitHub Desktop.
My try to problem C of Google Code Jame QR 2018
import sys, copy;
def solve():
return 0;
def getSomeOpenCell(sm, nm, em, wm, m):
result = {}
for i in range(sm-nm+1):
for j in range(em-wm+1):
#print i, j, nm + i, wm + j, m[nm + i][wm + j]
if m[nm + i][wm + j] == 0:
result["c"] = nm + i;
result["d"] = wm + j;
#print nm + i, wm + j, i, j, sm, nm, em, wm, result;
return result;
return result;
t = int(raw_input())
for i in range(1, t + 1):
a = int(raw_input())
m = [ [0] * 1000 for _ in range(1000)]
c = 500
d = 500
x = True
northmost = None
southmost = None
westmost = None
eastmost = None
while x:
print c, d
a,b=map(int, raw_input().split())
x = not ((a == 0 and b == 0) or (a == -1 and b == -1))
#print >> sys.stderr, x
#print >> sys.stderr, a
#print >> sys.stderr, b
m[a][b] = 1
if northmost == None or northmost > a:
northmost = a
if southmost == None or southmost < a:
southmost = a
if westmost == None or westmost > b:
westmost = b
if eastmost == None or eastmost < b:
eastmost = b
#print northmost, southmost, westmost, eastmost
"""for i in range(5):
print >> sys.stderr, [m[500 + j - 2][500 + i - 2] for j in range(5)]
for i in range(southmost-northmost):
print >> sys.stderr, [m[westmost + j][northmost + i] for j in range(eastmost-westmost)]"""
free = getSomeOpenCell(southmost, northmost, eastmost, westmost, m);
#print >> sys.stderr, free
if not "c" in free or not "d" in free:
print eastmost + 1, eastmost + 1 < 999
corners=[1000-eastmost, 1000 - southmost, westmost, northmost]
maxcorner = max(corners);
if 1000-eastmost == maxcorner and eastmost + 1 < 999:
c = northmost
d = eastmost + 1
elif 1000-southmost == maxcorner and southmost + 1 < 999:
c = southmost + 1
d = westmost
elif westmost == maxcorner and westmost - 1 > 1:
c = northmost
d = westmost - 1
elif northmost == maxcorner and northmost - 1 > 1:
c = northmost - 1
d = westmost
else:
c = northmost
d = westmost
else:
c = free["c"]
d = free["d"]
"""for i in range(southmost-northmost):
for j in range(eastmost-westmost):
if a[i][j] == 0:
c = i;
d = j;
print >> sys.stderr, [m[westmost + j][northmost + i] for j in range(eastmost-westmost)]
for i in range(5):
print >> sys.stderr, [m[500 + j - 2][500 + i - 2] for j in range(5)]
if (c == a and b == d):
c += 1
else:
r = abs(c - a) + abs(d-b)
if r == 2:
if a > c:
c+=1
else:
c-=1;"""
#v = map(int, raw_input().split())
#print "Case #" + str(i) + ": " + str(solve(n,v))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment