Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import math
- import collections
- # Save humans, destroy zombies!
- def Sqr(a):
- return a*a
- def Distance(p1, p2):
- return math.sqrt(Sqr(p2.y-p1.y)+Sqr(p2.x-p1.x))
- def saveable(dzh, dph):
- print (str(dzh/402) + "|" + str((dph-2000)/1000), file=sys.stderr)
- if (dzh/400 > (dph-2000)/1000):
- print("VALID", file=sys.__stderr__)
- return 1
- else:
- print("FALSE", file=sys.__stderr__)
- return 0
- def IsonCircle(center_x,center_y,radius,x,y):
- if ((x - center_x)^2 + (y - center_y)^2 < radius^2):
- return (1)
- else:
- return (0)
- def stacked(zombies):
- stack_z = 0
- stack_nbmax = 0
- for i in range(len(zombies)):
- tmp = 0
- for k in range(len(zombies)):
- tmp = tmp + IsonCircle(zombies[i].x, zombies[i].y, 400, zombies[j].x, zombies[j].y)
- if tmp > stack_nbmax:
- stack_nbmax = tmp
- stack_z = i
- zombies[i] = zombies[i]._replace(s=stack_nbmax)
- print(str(stack_nbmax), file=sys.__stderr__)
- return zombies[stack_z]
- def moyenne(a, b):
- return int((a+b)/2)
- # game loop
- s_human = collections.namedtuple("Human", "id x y")
- s_zombie = collections.namedtuple("Zombie", "id x y x2 y2 s")
- s_dist = collections.namedtuple("Dist", "d h z ")
- while 1:
- human_list = []
- dist_list = []
- zombie_list = []
- x, y = [int(i) for i in input().split()]
- dist = -1
- player = s_human("p", x, y)
- human_count = int(input())
- for i in range(human_count):
- human_id, human_x, human_y = [int(j) for j in input().split()]
- human_list.append(s_human(human_id, human_x, human_y))
- zombie_count = int(input())
- for i in range(zombie_count):
- zombie_id, zombie_x, zombie_y, zombie_xnext, zombie_ynext = [int(j) for j in input().split()]
- zombie_list.append(s_zombie(zombie_id, zombie_x, zombie_y, zombie_xnext, zombie_ynext, 0))
- for i in range(len(human_list)):
- print("loop", file=sys.stderr)
- tmp_d = Distance(human_list[i], zombie_list[0])
- tmp_z = 0
- for j in range(len(zombie_list)):
- if (tmp_d > Distance(human_list[i], zombie_list[j])):
- tmp_d = Distance(human_list[i], zombie_list[j])
- tmp_z = j
- print(str(human_list[i].id), file=sys.stderr)
- dist_list.append(s_dist(tmp_d, human_list[i], zombie_list[tmp_z]))
- j = 0
- while saveable(dist_list[j].d, Distance(dist_list[j].z, player)) != 1:
- j = j + 1
- target = dist_list[j]
- for i in range(len(dist_list)):
- if (saveable(dist_list[i].d, Distance(dist_list[i].z, player)) == 1 and target.d > dist_list[i].d):
- target = dist_list[i]
- k = 0
- for i in range(len(dist_list)):
- if (dist_list[i].d > Distance(dist_list[i].z, player)):
- k = k + 1
- farest_zombie = zombie_list[0]
- smallest_zombie = zombie_list[0]
- for i in range(len(zombie_list)):
- if (Distance(farest_zombie, player) < Distance(zombie_list[i], player)):
- farest_zombie = zombie_list[i]
- if (Distance(smallest_zombie, player) > Distance(zombie_list[i], player)):
- smallest_zombie = zombie_list[i]
- smallest_human = human_list[0]
- for i in range(len(human_list)):
- if Distance(smallest_human, player) > Distance(human_list[i], player):
- smallest_human = human_list[i]
- if (k == len(dist_list)):
- print("JE SUIS LA FRER", file=sys.stderr)
- zombie_stack = stacked(zombie_list)
- if (zombie_stack.s > 2):
- print(str(zombie_stack.x)+" "+str(zombie_stack.y))
- else:
- print(str(int(smallest_zombie.x))+" "+str(smallest_zombie.y))
- else:
- print(str(int(target.z.x))+" "+str(int(target.z.y)))
- # print(str(int((target.z.x+target.h.x)/2)) + " " + str(int((target.z.y+target.h.y)/2)))
- dist_list.clear
- zombie_list.clear
- human_list.clear
- # Write an action using print
- # To debug: print("Debug messages...", file=sys.stderr)
- # Your destination coordinates
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement