Advertisement
Guest User

Esteban

a guest
Jul 27th, 2010
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. # *-* coding: utf-8 *-*
  2.  
  3. from __future__ import division
  4.  
  5. import sys
  6.  
  7. DEBUG = False
  8.  
  9. def where_should_i_ve_been(z):
  10.     return ['B' if not i[1] or (i[0] and 700*(i[1]+1) < 300*(i[0])) else 'A' for i in z]
  11.  
  12. def money_awarded(z, y):
  13.     retval = 0
  14.     for i in xrange(len(z)):
  15.         retval += 700/(z[i][0]+1) if y[i] == 'A' else 300/(z[i][1]+1)
  16.     return retval
  17.  
  18. # x represents the history of populations
  19. x = []
  20. # y represents my choices
  21. y = []
  22. # z represents the history - my choices
  23. z = []
  24.  
  25. for i in xrange(10):
  26.     sys.stdout.write('A\n')
  27.     sys.stdout.flush()
  28.     line = sys.stdin.readline()
  29.     x.append(map(int, line.strip().split(' ')))
  30.     y.append('A')
  31.     z.append([x[i][0]-1, x[i][1]])
  32.  
  33. for i in xrange(70):
  34.     evaluations = []
  35.     for ps in xrange(1, int(len(x)/2)):
  36.         inter = where_should_i_ve_been(z[-2*ps:-ps])
  37.         evaluations += [(money_awarded(z[-2*ps:], inter*2)/ps, inter)]
  38.         if DEBUG:
  39.             print ps, z[-2*ps:-ps], inter, evaluations[-1]
  40.     best = max(evaluations)
  41.     sys.stdout.write(best[1][0]+'\n')
  42.     sys.stdout.flush()
  43.     line = sys.stdin.readline()
  44.     x.append(map(int, line.strip().split(' ')))
  45.     y.append(best[1][0])
  46.     z.append([x[i][0]-(1 if best[1][0] == 'A' else 0), x[i][1]-(1 if best[1][0] == 'B' else 0)])
  47.  
  48. if DEBUG:
  49.     print y
  50.     print "Mi elección:", money_awarded(z, y)
  51.     print "A constante:", money_awarded(z, ['A' for a in xrange(len(z))])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement