Advertisement
Guest User

Problem statement

a guest
Apr 30th, 2019
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. Problem statement:
  2.  
  3. The Galactica spaceship must escape from Cylon persecution. Moreover, Adama (Battlestar Galactica's commander) and Laura Roslin (President of the 12 Colonies) want to reach a new home for humanity.
  4. Right now, Galactica is waiting on a planet and wants to go to New Earth (Adama knows where it is).
  5. But, to avoid being caught by the Cylon, Adama is planning to visit some other planets before heading towards the final destination.
  6. Gaius Baltar is a little busy right now, so you will be the one who saves humanity.
  7. And, just to be sure it's worth the trouble, Adama asks you how many different paths can be taken from your current planet to the final destination.
  8.  
  9. Because of some complicated laws of physics, you can't go everywhere from every planet. And, because you don't want to backtrack,
  10. the Battlestar must always go forwards to another planet that’s allowed by the laws of hyperspace jumps, so there can't be any loops. See the chart showing possible situations for an explanation.
  11.  
  12. In order to explain all above, let’s see this graph, that represents a possible situation:
  13.  
  14. https://i.stack.imgur.com/Bvb2v.png
  15.  
  16.  
  17. How many paths are there for the Galactica to reach New Earth? If you count them you can see there are 5 different paths.
  18.  
  19. Path 1: Galactica -> A -> E -> New Earth
  20. Path 2: Galactica -> A -> D -> F -> New Earth
  21. Path 3: Galactica -> B -> D -> F -> New Earth
  22. Path 4: Galactica -> C -> D -> F -> New Earth
  23. Path 5: Galactica -> C -> F -> New Earth
  24. Your goal is to help Adama and Laura by writing a program that will output the number of different paths to reach New Earth given a random map like the one above so they can make a decision.
  25.  
  26. Assumptions:
  27.  
  28. The map has no loops. From any given planet you can only go forward to another planet.
  29. There is at least one path to every planet, except the planet where the Galactica is waiting (the initial planet).
  30. All planets, except New Earth which is the final planet, have at least one path to move forwards.
  31.  
  32. Input
  33. The first line of the file has the number of cases. Each case starts with a line containing the number P of planets from which you are able to jump. After that there is one line for every planet (except “New Earth”) with a comma separated list of allowed hyperspace jumps for that planet. So, each case will have this format:
  34.  
  35. P
  36. Galactica:Destination1,Destination2,..,DestinationM
  37. Destination1:DestinationX,DestinationY
  38. ...
  39. DestinationZ:New Earth
  40.  
  41. The first planet will always be named “Galactica” and the final planet will always be named “New Earth”.
  42.  
  43. Sample Input
  44.  
  45. 1
  46. 7
  47. Galactica:A,B,C
  48. A:E,D
  49. B:D
  50. C:D,F
  51. D:F
  52. E:New Earth
  53. F:New Earth
  54.  
  55.  
  56. Sample Output
  57.  
  58. Case #1: 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement