Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2010
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. You play the following game against a devilishly clever opponent. On the table, there are
  2. two bowls filled with glass beads. In each move, depending on whose turn it is, you or your
  3. opponent can do one of the following.
  4. � Move one bead from the first bowl to the second bowl.
  5. � Remove one bead from the second bowl.
  6. At any point in the game, let x denote the number of beads in the first bowl and y denote
  7. the number of beads in the second bowl. If x+ y is even, it is your turn to move. If x+ y is
  8. odd, it is your opponent�s turn to move.
  9. At each position of the game, you get some points that depend on the number of beads,
  10. x and y, in the two bowls. This is given by a function f(x, y) = Ax2 +By2 +Cxy, where A,
  11. B and C are integers that are fixed each time the game is played.
  12. The game starts with M beads in the first bowl and N beads in the second bowl. As the
  13. game progresses, beads are removed. The game ends when both bowls are empty.
  14. Your score for the game is the sum of the values f(x, y) for each position (x, y) that the
  15. game passes through, starting from (M,N) and ending with (0, 0). Your aim is to obtain
  16. as high a score as possible, no matter what moves your opponent chooses. Remember that
  17. your opponent is fiendishly ingenious and will always play in such a way as to minimize your
  18. score.
  19. For example, suppose the game starts with 2 beads in each bowl and the score function
  20. is f(x, y) = x2 − y2 − xy: that is, A = 1, B = −1 and C = −1. Here are some plays of
  21. the game�the positions where you choose the move are enclosed in boxes and the positions
  22. where your opponent moves are not enclosed in boxes.
  23. � (2,2) ! (2,1) ! (2,0) ! (1,1) ! (1,0) ! (0,1) ! (0,0).
  24. For this sequence of moves, your total score is f(2, 2) + f(2, 1) + f(2, 0) + f(1, 1) +
  25. f(1, 0) + f(0, 1) + f(0, 0) = (−4) + 1 + 4 + (−1) + 1 + (−1) + 0 = 0.
  26. � (2,2) ! (1,3) ! (0,4) ! (0,3) ! (0,2) ! (0,1) ! (0,0)
  27. For this sequence of moves, your total score is f(2, 2) + f(1, 3) + f(0, 4) + f(0, 3) +
  28. f(0, 2) + f(0, 1) + f(0, 0) = (−4) + (−11) + (−16) + (−9) + (−4) + (−1) + 0 = −45.
  29. In this particular game, the best possible score that you can achieve if you consider all
  30. possible moves that your opponent can choose is −22. Recall that your devilishly clever
  31. opponent always plays in such a way that your score is minimized.
  32. Input format
  33. The input consists of a single line containing five integers, M, N, A, B and C where M and
  34. N are the number of beads initially in the first and second bowl, respectively and A, B and
  35. C are the coefficients of the score function f(x, y) = Ax2 + By2 + Cxy.
  36. 3
  37. Output format
  38. The output should be a single integer, the maximum score that you can achieve in this game.
  39. Test data
  40. In all inputs, 1  M,N  600 and −1000  A,B,C  1000.
  41. Example
  42. Sample input
  43. 2 2 1 -1 -1
  44. Sample output
  45. -22
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement