Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.09 KB | None | 0 0
  1. import sys
  2. import math
  3. import collections
  4.  
  5.  
  6. # Save humans, destroy zombies!
  7. def Sqr(a):
  8.     return a*a
  9.  
  10. def Distance(p1, p2):
  11.     return math.sqrt(Sqr(p2.y-p1.y)+Sqr(p2.x-p1.x))
  12.  
  13. def saveable(dzh, dph):
  14.     print (str(dzh/402) + "|" + str((dph-2000)/1000), file=sys.stderr)
  15.     if (dzh/400 > (dph-2000)/1000):
  16.         print("VALID", file=sys.__stderr__)
  17.         return 1
  18.     else:
  19.         print("FALSE", file=sys.__stderr__)
  20.         return 0
  21.  
  22. def IsonCircle(center_x,center_y,radius,x,y):
  23.     if ((x - center_x)^2 + (y - center_y)^2 < radius^2):
  24.         return (1)
  25.     else:
  26.         return (0)
  27.  
  28. def stacked(zombies):
  29.     stack_z = 0
  30.     stack_nbmax = 0
  31.     for i in range(len(zombies)):
  32.         tmp = 0
  33.         for k in range(len(zombies)):
  34.             tmp = tmp + IsonCircle(zombies[i].x, zombies[i].y, 400, zombies[j].x, zombies[j].y)
  35.         if tmp > stack_nbmax:
  36.             stack_nbmax = tmp
  37.             stack_z = i
  38.             zombies[i] = zombies[i]._replace(s=stack_nbmax)
  39.     print(str(stack_nbmax), file=sys.__stderr__)
  40.     return zombies[stack_z]
  41.  
  42. def moyenne(a, b):
  43.     return int((a+b)/2)
  44.  
  45. # game loop
  46. s_human = collections.namedtuple("Human", "id x y")
  47. s_zombie = collections.namedtuple("Zombie", "id x y x2 y2 s")
  48. s_dist = collections.namedtuple("Dist", "d h z ")
  49. while 1:
  50.  
  51.     human_list = []
  52.     dist_list = []
  53.     zombie_list = []
  54.     x, y = [int(i) for i in input().split()]
  55.     dist = -1
  56.     player = s_human("p", x, y)
  57.    
  58.     human_count = int(input())
  59.     for i in range(human_count):
  60.         human_id, human_x, human_y = [int(j) for j in input().split()]
  61.         human_list.append(s_human(human_id, human_x, human_y))
  62.        
  63.     zombie_count = int(input())
  64.     for i in range(zombie_count):
  65.         zombie_id, zombie_x, zombie_y, zombie_xnext, zombie_ynext = [int(j) for j in input().split()]
  66.         zombie_list.append(s_zombie(zombie_id, zombie_x, zombie_y, zombie_xnext, zombie_ynext, 0))
  67.  
  68.  
  69.     for i in range(len(human_list)):
  70.         print("loop", file=sys.stderr)
  71.         tmp_d = Distance(human_list[i], zombie_list[0])
  72.         tmp_z = 0
  73.         for j in range(len(zombie_list)):
  74.             if (tmp_d > Distance(human_list[i], zombie_list[j])):
  75.                 tmp_d = Distance(human_list[i], zombie_list[j])
  76.                 tmp_z = j
  77.         print(str(human_list[i].id), file=sys.stderr)
  78.         dist_list.append(s_dist(tmp_d, human_list[i], zombie_list[tmp_z]))
  79.        
  80.     j = 0
  81.     while saveable(dist_list[j].d, Distance(dist_list[j].z, player)) != 1:
  82.         j = j + 1
  83.     target = dist_list[j]
  84.     for i in range(len(dist_list)):
  85.         if (saveable(dist_list[i].d, Distance(dist_list[i].z, player)) == 1 and target.d > dist_list[i].d):
  86.             target = dist_list[i]
  87.     k = 0
  88.     for i in range(len(dist_list)):
  89.         if (dist_list[i].d > Distance(dist_list[i].z, player)):
  90.             k = k + 1
  91.     farest_zombie = zombie_list[0]
  92.     smallest_zombie = zombie_list[0]
  93.     for i in range(len(zombie_list)):
  94.         if (Distance(farest_zombie, player) < Distance(zombie_list[i], player)):
  95.             farest_zombie = zombie_list[i]
  96.         if (Distance(smallest_zombie, player) > Distance(zombie_list[i], player)):
  97.             smallest_zombie = zombie_list[i]
  98.     smallest_human = human_list[0]
  99.     for i in range(len(human_list)):
  100.         if Distance(smallest_human, player) > Distance(human_list[i], player):
  101.             smallest_human = human_list[i]
  102.     if (k == len(dist_list)):
  103.         print("JE SUIS LA FRER", file=sys.stderr)
  104.         zombie_stack = stacked(zombie_list)
  105.         if (zombie_stack.s > 2):
  106.             print(str(zombie_stack.x)+" "+str(zombie_stack.y))
  107.         else:
  108.             print(str(int(smallest_zombie.x))+" "+str(smallest_zombie.y))
  109.     else:
  110.         print(str(int(target.z.x))+" "+str(int(target.z.y)))
  111.           #  print(str(int((target.z.x+target.h.x)/2)) + " " + str(int((target.z.y+target.h.y)/2)))
  112.     dist_list.clear
  113.     zombie_list.clear
  114.     human_list.clear
  115.     # Write an action using print
  116.     # To debug: print("Debug messages...", file=sys.stderr)
  117.  
  118.     # Your destination coordinates
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement