Guest User

Acution

a guest
Jan 24th, 2012
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. #!/usr/bin/python2
  2.  
  3. f = open('auction.txt')
  4. s = f.read()
  5. f.close()
  6.  
  7. def genereer(n,p1,w1,m,k,a,b,c,d):
  8.     p = []
  9.     w = []
  10.    
  11.     p.append(p1)
  12.     w.append(w1)
  13.    
  14.     for i in xrange(1,n):
  15.         p.append( ((a*p[i-1] + b) % m) + 1)
  16.         w.append( ((c*w[i-1] + d) % k) + 1)
  17.     return (p,w)
  18.    
  19. def koopjes((products,weights)):
  20.     totaal = 0
  21.     for (p,w) in zip(products,weights):
  22.         n = 0
  23.         for (p1,w1) in zip(products,weights):
  24.             if p1 < p and not w1 > w:
  25.                 n += 1
  26.             if w1 < w and not p1 > p:
  27.                 n += 1
  28.         if n == 0:
  29.             totaal += 1
  30.        
  31.     return totaal
  32.  
  33. def dure((products,weights)):
  34.     totaal = 0
  35.     for (p,w) in zip(products,weights):
  36.         n = 0
  37.         for (p1,w1) in zip(products,weights):
  38.             if p < p1 and not w > w1:
  39.                 n += 1
  40.             if w < w1 and not p > p1:
  41.                 n += 1
  42.         if n == 0:
  43.             totaal += 1
  44.        
  45.     return totaal
  46.    
  47.    
  48.  
  49. print genereer(5,1,4,5,7,1,0,1,2)
  50.  
  51. #print koopjes(genereer(5,1,4,5,7,1,0,1,2))
  52. #print dure(genereer(5,1,4,5,7,1,0,1,2))
  53.  
  54. f = open('auction_out.txt', 'w')
  55. l = s.split('\n')
  56. for c in range(1,int(l[0])+1):
  57.     s = l[c].split(' ')
  58.     #n,p1,w1,m,k,a,b,c,d
  59.     n = int(s[0])
  60.     p1 = int(s[1])
  61.     w1 = int(s[2])
  62.     m = int(s[3])
  63.     k = int(s[4])
  64.     a = int(s[5])
  65.     b = int(s[6])
  66.     cc = int(s[7])
  67.     d = int(s[8])
  68.     g = genereer(n,p1,w1,m,k,a,b,cc,d)
  69.     #print "Case #" + str(c) + ": " + str(dure(genereer(n,p1,w1,m,k,a,b,cc,d))) + " " + str(koopjes(genereer(n,p1,w1,m,k,a,b,cc,d)))
  70.     f.write("Case #" + str(c) + ": " + str(dure(g)) + " " + str(koopjes(g)) + '\n')
  71. f.close()
Advertisement
Add Comment
Please, Sign In to add comment