Guest User

Untitled

a guest
Jan 2nd, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. You have encountered a new fancy online auction that offers lots of products. You are only interested in their price and weight. We shall say that product A is strictly preferred over product B if A costs less than B and is not heavier (they may be of equal weight) or if A weighs less and is not more expensive (they can have equal price).
  2. We shall call a product A a bargain if there is no product B such that B is better than A. Similarly, we shall call a product C a terrible deal if there exists no product D such that C is better than D. Note that according to our definitions, the same product may be both a bargain and a terrible deal! Only wacky auctioneers sell such products though.
  3. One day you wonder how many terrible deals and bargains are offered. The number of products, N, is too large for your human-sized brain though. Fortunately, you discovered that the auction manager is terribly lazy and decided to sell the products based on a very simple pseudo-random number generator.
  4. If product i has price Pi and weight Wi, then the following holds for product i+1:
  5. Pi = ((A*Pi-1 + B) mod M) + 1 (for all i = 2..N)
  6. Wi = ((C*Wi-1 + D) mod K) + 1 (for all i = 2..N)
  7. You carefully calculated the parameters for the generator (P1, W1, M, K, A, B, C and D). Now you want to calculate the number of terrible deals and bargains on the site.
  8. Input
  9. The first line of the input file contains a single integer T: the number of test cases. T lines follow, each representing a single test case with 9 space-separated integers: N, P1, W1, M, K, A, B, C and D.
  10. Output
  11. Output T lines, one for each test case. For each case, output "Case #t: a b", where t is the test case number (starting from 1), a is the number of terrible deals and b is the number of bargains.
  12. Constraints
  13. 1 ≤ T ≤ 20
  14. 1 ≤ N ≤ 1018
  15. 1 ≤ M, K ≤ 107
  16. 1 ≤ P1 ≤ M
  17. 1 ≤ W_1 ≤ K
  18. 0 ≤ A,B,C,D ≤ 109
  19.  
  20. Example Input:
  21.  
  22. 5
  23. 5 1 4 5 7 1 0 1 2
  24. 3 1 3 3 3 1 0 1 1
  25. 8 1 3 3 3 1 0 1 2
  26. 13 5 7 5 9 1 3 2 5
  27. 11 2 3 5 7 11 13 17 19
  28.  
  29.  
  30. Example Output:
  31.  
  32. Case #1: 3 3
  33. Case #2: 3 3
  34. Case #3: 2 3
  35. Case #4: 2 2
  36. Case #5: 3 1
Advertisement
Add Comment
Please, Sign In to add comment