jli

Untitled

jli
Feb 26th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. Problem Statement
  2. Suppose you had an n by n chess board and a super piece called a kingknight. Using only one move the kingknight denoted 'K' below can reach any of the spaces denoted 'X' or 'L' below:
  3. .......
  4. ..L.L..
  5. .LXXXL.
  6. ..XKX..
  7. .LXXXL.
  8. ..L.L..
  9. .......
  10. In other words, the kingknight can move either one space in any direction (vertical, horizontal or diagonally) or can make an 'L' shaped move. An 'L' shaped move involves moving 2 spaces horizontally then 1 space vertically or 2 spaces vertically then 1 space horizontally. In the drawing above, the 'L' shaped moves are marked with 'L's whereas the one space moves are marked with 'X's. In addition, a kingknight may never jump off the board.
  11.  
  12.  
  13.  
  14. Given the size of the board, the start position of the kingknight and the end position of the kingknight, your method will return how many possible ways there are of getting from start to end in exactly numMoves moves. start and finish are int[]s each containing 2 elements. The first element will be the (0-based) row position and the second will be the (0-based) column position. Rows and columns will increment down and to the right respectively. The board itself will have rows and columns ranging from 0 to size-1 inclusive.
  15.  
  16.  
  17.  
  18. Note, two ways of getting from start to end are distinct if their respective move sequences differ in any way. In addition, you are allowed to use spaces on the board (including start and finish) repeatedly during a particular path from start to finish. We will ensure that the total number of paths is less than or equal to 2^63-1 (the upper bound for a long).
  19.  
  20. Definition
  21.  
  22. Class: ChessMetric
  23. Method: howMany
  24. Parameters: int, int[], int[], int
  25. Returns: long
  26. Method signature: long howMany(int size, int[] start, int[] end, int numMoves)
  27. (be sure your method is public)
  28.  
  29.  
  30. Notes
  31. - For C++ users: long long is a 64 bit datatype and is specific to the GCC compiler.
  32.  
  33. Constraints
  34. - size will be between 3 and 100 inclusive
  35. - start will contain exactly 2 elements
  36. - finish will contain exactly 2 elements
  37. - Each element of start and finish will be between 1 and size-1 inclusive
  38. - numMoves will be between 1 and 50 inclusive
  39. - The total number of paths will be at most 2^63-1.
  40.  
  41. Examples
  42. 0)
  43.  
  44. 3
  45. {0,0}
  46. {1,0}
  47. 1
  48. Returns: 1
  49. Only 1 way to get to an adjacent square in 1 move
  50. 1)
  51.  
  52. 3
  53. {0,0}
  54. {1,2}
  55. 1
  56. Returns: 1
  57. A single L-shaped move is the only way
  58. 2)
  59.  
  60. 3
  61. {0,0}
  62. {2,2}
  63. 1
  64. Returns: 0
  65. Too far for a single move
  66. 3)
  67.  
  68. 3
  69. {0,0}
  70. {0,0}
  71. 2
  72. Returns: 5
  73. Must count all the ways of leaving and then returning to the corner
  74. 4)
  75.  
  76. 100
  77. {0,0}
  78. {0,99}
  79. 50
  80. Returns: 243097320072600
  81. This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
Advertisement
Add Comment
Please, Sign In to add comment