Advertisement
Guest User

Untitled

a guest
Aug 7th, 2010
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # Modadicto Aleatorio
  5. # idea por Marcos
  6.  
  7. import sys
  8. from random import choice, randint
  9.  
  10. A_TOTAL = 700.0
  11. B_TOTAL = 300.0
  12.  
  13. times_won = {"A" : 0, "B": 0}
  14.  
  15. # En el primer turno, la probabilidad de cada feudo es 1/2.
  16. print choice(["A", "B"])
  17. sys.stdout.flush()
  18.  
  19.  
  20. while(True):
  21.     # Siempre elige un feudo aleatorio, pero la probabilidad de elegir cada
  22.     # feudo será proporcional a la cantidad de veces que ese feudo dio más
  23.     # dinero a cada familia
  24.    
  25.     # Ejemplo: si pasaron 19 turnos y el feudo A dio más plata 13 turnos y
  26.     # el B dio más plata 6 turnos, la probabilidad de ir al A serán 13 / 19
  27.     # y la de ir al B serán 6 / 19.
  28.  
  29.    
  30.     a,b = sys.stdin.readline().strip().split(" ")
  31.     best_payer = "A" if int(a) == 0 else "B"
  32.     if "0" not in [a,b]:
  33.         best_payer = "A" if (A_TOTAL/int(a))>(B_TOTAL/int(b)) else "B"
  34.     times_won[best_payer] += 1
  35.    
  36.     r = randint(0, times_won["A"] + times_won["B"] - 1)
  37.     print "A" if r < times_won["A"] else "B"
  38.      
  39.     sys.stdout.flush()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement