Vassil_Iliev

shit

Mar 26th, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.61 KB | None | 0 0
  1. Scrooge McDuck
  2. Description
  3. Scrooge McDuck likes his treasure very much. That is why he likes to play a funny game.
  4.  
  5. He builds a labyrinth of coins and tries to escape from it. You can think of the labyrinth as a rectangular field. Each cell of the field contains 0 or more coins.
  6.  
  7. When Scrooge McDuck steps on a cell, he can take only a single coin from this cell, and only if there are any coins. Scrooge McDuck can escape the field, only if he is surrounded by empty cells.
  8.  
  9. Scrooge McDuck always wants to go to the neighbouring cell with most coins. BUT if there are more than one cells with the same amount of coins (the largest), he chooses a cell (always the largest) from the order left, right, up, down
  10.  
  11. If Scrooge McDuck cannot go in any direction, he is out of the labyrinth
  12.  
  13. Examples
  14.  
  15. Scrooge McDuck is worried, not about his life, but if the coins he collect will be enough. Your task is to tell him how many coins he will collect, following the rules above.
  16.  
  17. Input
  18. Read from the standard input
  19. On the first line find N and M
  20. The size of the labyrinth
  21. On the next N lines find M integer values, separated by a space
  22. The input data will always be valid and there is no need to check it explicitly
  23. The starting location of Scrooge McDuck will be marked as the only 0
  24. Output
  25. Print to the standard output
  26. On the single line, print the number of coins Scrooge McDuck can collect, following the rules
  27. Contraints
  28. 2 <= N <= 10
  29. 2 <= M <= 10
  30. Each cell can contain up to 1024 coins
  31. Sample tests
  32. Input
  33. 4 3
  34. 3 2 4
  35. 2 0 3
  36. 1 1 5
  37. 2 2 5
  38. Output
  39. 22
  40. Input
  41. 3 3
  42. 10 10 0
  43. 10 10 10
  44. 10 10 10
  45. Output
  46. 78
  47. Input
  48. 3 3
  49. 10 10 10
  50. 10 0 10
  51. 10 10 10
  52. Output
  53. 80
  54. Input
  55. 2 3
  56. 0 5 2
  57. 2 5 3
  58. Output
  59. 15
  60.  
  61. ///////////////////////////////////////////////////////////////////
  62.  
  63. Matrix Max Sum
  64. Description
  65. Write a program that finds the maximum sum between two given coordinates in a matrix. The coordinates are provided as a list of pairs, such as 2 3 -4 -2 where 2 3 is the first pair and -4 -2 is the next one. The first number of the pair is the row coordinate R and the second one is the column coordinate C.
  66.  
  67. You need to follow a path from R to C and sum up all the values you encounter in cells. For example, with coordinates 2 3 you start from the beginning of the 2nd row and move towards the 3rd column. When you reach the column, you go up because the column coordinate 3 is positive.
  68.  
  69. With coordinates -4 -2 you start from the end of the 4th row (because -4 is negative) and move towards the 2nd column. When you reach it, you go down (-2 is negative).
  70.  
  71. Check the following picture for a clearer idea.
  72.  
  73. table
  74.  
  75. The path 2 3 yields a sum of 17 which is higher than the sum you obtain by following -4 -2 (15)
  76.  
  77. Print the maximum sum you find to the standard output.
  78.  
  79. Note
  80. You always have to move horizontally in rows and vertically in columns. For example, in the above picture, the correct path with coordinates -4 -2 is 3 -> 2 -> 5 -> 3 -> 2 and NOT 3 -> 4 -> 3 -> 6 -> 2.
  81.  
  82. Input
  83. On the first line, you receive an integer N - the number of rows in the matrix
  84. On the next N lines, each row of the matrix is given, with columns separated by a space
  85. On the last line, the R and C coordinates are given, separated by spaces
  86. Output
  87. On the only line of output, print the maximum sum found.
  88. Constraints
  89. N will be an integer between 5 and 20, inclusive.
  90. All rows have the exact same length, also between 5 and 20, inclusive.
  91. The R and C coordinates will always be valid and inside the matrix.
  92. The R C pairs will be at least 1 and no more than 20.
  93. Matrix elements will have values in range -5000 and 5000.
  94. Sample Tests
  95. Input
  96. 6
  97. 1 2 3 4 5 6
  98. 2 3 4 5 6 7
  99. 6 5 4 3 2 1
  100. 3 4 5 6 7 8
  101. 4 5 6 7 8 9
  102. 9 8 7 6 5 4
  103. 3 5 3 -5 -4 -2
  104. Output
  105. 43
  106. Input
  107. 5
  108. 1 22 3 41 5 2
  109. 2 13 4 -5 6 5
  110. -6 5 9 31 2 8
  111. 3 14 5 -6 7 4
  112. 4 -5 6 -7 8 7
  113. -3 -3 3 3 4 -3 -4 3
  114. Output
  115. 61
  116.  
  117. ////////////////////////////////////////////////////////////////////
  118.  
  119. Jump Around
  120. Description
  121. Pesho is a funny cangaroo. He wants to jump around all day and night. Yet his mom is not so happy about that, she doesn't let him out. Of course Pesho tried many times to escape, but his mother used to be the National Cangaroo jump champion, so she can jump faster and higher than him. Still she is not that smart, so Pesho decided that he can trick her by jumping using a sequence of jumps.
  122.  
  123. Your task is to calculate if Pesho can escape from his mother, using the given sequence of jumps.
  124.  
  125. You are given a field of size N x M where the values are as follows: On the first row the numbers are from 1 to M, on the second row – from M+1 to 2*M, on the third – from 2*M +1 to 3*M, etc…
  126.  
  127. By given position in the field, and using the patterns given, calculate if Pesho can escape from his mother.
  128.  
  129. Examples
  130.  
  131. You are also given a sequence of jumps over the field. The jumps are described with change to the row and column, i.e. when on position (R, C) with jump (-2, 3), Pesho will go to position (R-2, C+3).
  132. When the sequence of jumps is over, Pesho must start the same sequence again.
  133.  
  134. If Pesho goes outside the field, he has escaped, if Pesho goes to a previously visited position, he is caught.
  135.  
  136. Input
  137. Read from the standard input
  138.  
  139. On the first line, find the numbers N, M and J. (J is number of jumps)
  140. On the second line, find the start position, R and C
  141. On the next J lines, find the jumps
  142. Output
  143. Print on the standard output
  144.  
  145. On the single line, print
  146. "escaped SUM_OF_NUMBERS", if Pesho escapes his mother
  147. "caught NUMBER_OF_JUMPS", if Pesho is caught
  148. Constraints
  149. N and M will always be between 1 and 500
  150. J will be between 1 and 1000
  151. Sample tests
  152. Input
  153. 6 7 3
  154. 0 0
  155. 2 2
  156. -2 2
  157. 3 -1
  158. Output
  159. escaped 89
Advertisement
Add Comment
Please, Sign In to add comment