Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. ### Canadian Computing Competition: 2008 Stage 1, Senior #3
  2.  
  3. In order to make a few dollars, you have decided to become part of a scientific experiment. You are fed lots of pizza, then more pizza and then you are asked to find your way across the city on a scooter powered only by pizza. Of course, the city has lots of intersections, and these intersections are very controlled. Some intersections are forbidden for you to enter; some only let you move north/south as you leave the intersection; others let you move only east/west as you leave the intersection; and the rest let you go in any compass direction (north, south, east or west).
  4.  
  5. Thankfully your scientific friends have given you a map of the city (on the back of a pizza box), with an arrangement of symbols indicating how you can move around the city. Specifically, there are 4 different symbols on the box:
  6.  
  7. * The symbol `+` indicates we can move in any direction (north/south/east/west) from this location.
  8. * The symbol `-` indicates we can move only east or west from this location.
  9. * The symbol `|` indicates we can move only north or south from this location.
  10. * The symbol `*` indicates we cannot occupy this location.
  11.  
  12. Your task is to determine how many intersections you must pass through to move from the north-west corner of the city to the south-east corner of the city.
  13.  
  14. ## Input Specification
  15.  
  16. The input begins with a number ~t~ ~(1 \le t \le 10)~ on its own line, which indicates how many different cases are contained in this file. Each case begins with a number ~r~ on one line, followed by a number ~c~ on the next line ~(1 \le r, c \le 20)~. The next ~r~ lines contain ~c~ characters, where each character is one of {`+`, `*`, `-`, `|`}. You may assume the north-west corner of the city can be occupied (i.e., it will not be marked with `*`).
  17.  
  18. ## Output Specification
  19.  
  20. The output will be ~t~ lines long, with one integer per line. The integer on line ~i~ ~(1 \le i \le t)~ indicates the minimum number of intersections required to pass through as you move from the north-west corner of the city to the south-east corner of the city. If there is no way to get from the north-west corner to the south-east corner, output `-1` for that test case.
  21.  
  22. ## Sample Input
  23.  
  24. 3
  25. 2
  26. 2
  27. -|
  28. *+
  29. 3
  30. 5
  31. +||*+
  32. +++|+
  33. **--+
  34. 2
  35. 3
  36. +*+
  37. +*+
  38.  
  39. ## Output for Sample Input
  40.  
  41. 3
  42. 7
  43. -1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement