Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. const [trainCars, numTickets, numRoutes] = readline().split(' ').map(n => +n)
  2. const colors = ['red', 'yellow', 'green', 'blue', 'white', 'black', 'orange', 'pink', 'engine']
  3.  
  4. // Player's hand: for each color type, a number of cards
  5. const hand = {}
  6. readline().split(' ').forEach((num, i) => {
  7. hand[colors[i]] = +num
  8. })
  9.  
  10. // Player's tickets: two cities and a number of earned points
  11. const tickets = Array.from({length: numTickets}, () => {
  12. const [p, from, to] = readline().split(' ')
  13. return {points: +p, from, to}
  14. }).sort((a, b) => b.points - a.points)
  15.  
  16. // Possible routes: two cities, a number of required cards and engines
  17. const routes = Array.from({length: numRoutes}, () => {
  18. const [l, e, c, from, to] = readline().split(' ')
  19. return {length: +l, requiredEngines: +e, color: c.toLowerCase(), from, to}
  20. })
  21.  
  22. // Graph of cities, by name. Contains an array of linked cities (route index)
  23. const mapGraph = {}
  24. routes.forEach(({from, to}, i) => {
  25. if (!(from in mapGraph)) {
  26. mapGraph[from] = []
  27. }
  28. mapGraph[from].push(i)
  29. if (!(to in mapGraph)) {
  30. mapGraph[to] = []
  31. }
  32. mapGraph[to].push(i)
  33. })
  34.  
  35. /*printErr(JSON.stringify(hand, null, 2))
  36. printErr(JSON.stringify(tickets, null, 2))
  37. printErr(JSON.stringify(routes, null, 2))
  38. printErr(JSON.stringify(mapGraph, null, 2))*/
  39.  
  40. const computeRouteScore = route => {
  41. switch(route.length) {
  42. case 1: return 1
  43. case 2: return 2
  44. case 3: return 4
  45. case 4: return 7
  46. case 6: return 15
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement