Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Numerics;
  4.  
  5. namespace Bounce
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int[] input = new int[2];
  12. input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  13. BigInteger[,] matrix = new BigInteger[input[0], input[1]];
  14. int n = input[0];
  15. int m = input[1];
  16. //declare matrix
  17. string direction = "downRight";
  18. int startingRow = 0;
  19. int startingCol = 0;
  20. BigInteger sum = 1;
  21. //fill matrix with correct vallues
  22. for (int row = 0; row < n; row++)
  23. {
  24. for (int col = 0; col < m; col++)
  25. {
  26. matrix[row, col] = (int)Math.Pow(2, row + col);
  27. }
  28. }
  29. while (true)
  30. {
  31.  
  32. if (direction == "downRight")
  33. {
  34. startingRow++;
  35. startingCol++;
  36. sum += matrix[startingRow, startingCol];
  37. if (startingRow == n-1 || startingCol == m-1)
  38. {
  39. if (startingRow == n-1)
  40. {
  41. direction = "rightUp";
  42. }
  43. else
  44. {
  45. direction = "downLeft";
  46. }
  47. }
  48. }
  49. if (direction == "rightUp")
  50. {
  51. startingRow--;
  52. startingCol++;
  53. sum += matrix[startingRow, startingCol];
  54.  
  55. if (startingRow == 0 || startingCol == m-1)
  56. {
  57. if (startingCol == m-1)
  58. {
  59. direction = "upLeft";//To Do: direction = "upRight";
  60. }
  61. else
  62. {
  63. direction = "downRight"; //To Do: direction = "upLeft";
  64. }
  65. }
  66. }
  67. if (direction == "downLeft")
  68. {
  69. startingRow++;
  70. startingCol--;
  71. sum += matrix[startingRow, startingCol];
  72.  
  73. if (startingRow == n - 1 || startingCol == 0)
  74. {
  75. if (startingCol == 0)
  76. {
  77. direction = "downRight";
  78. }
  79. else
  80. {
  81. direction = "upLeft";
  82. }
  83. }
  84. }
  85. if (direction == "upLeft")
  86. {
  87. startingRow--;
  88. startingCol--;
  89. sum += matrix[startingRow, startingCol];
  90.  
  91. if (startingRow == 0 || startingCol == 0)
  92. {
  93. if (startingCol == 0)
  94. {
  95. direction = "upRight";
  96. }
  97. else
  98. {
  99. direction = "downLeft";
  100. }
  101. }
  102.  
  103. }
  104.  
  105. if (direction == "downLeft")
  106. {
  107. startingRow++;
  108. startingCol--;
  109. sum += matrix[startingRow, startingCol];
  110.  
  111. if (startingRow == n-1 || startingCol == 0)
  112. {
  113. if (startingCol == 0)
  114. {
  115. direction = "downRight";
  116. }
  117. else
  118. {
  119. direction = "upLeft";
  120. }
  121. }
  122.  
  123. }
  124. if (direction == "upRight")
  125. {
  126. startingRow--;
  127. startingCol++;
  128. sum += matrix[startingRow, startingCol];
  129.  
  130. if (startingRow == 0 || startingCol == m-1)
  131. {
  132. if (startingRow == 0)
  133. {
  134. direction = "downRight";
  135. }
  136. else
  137. {
  138. direction = "upLeft";
  139. }
  140. }
  141.  
  142. }
  143. if (direction == "upRight" || direction == "upLeft" || direction == "downLeft" || direction == "downRight" || direction == "rightUp" || direction == "downLeft")
  144. {
  145. if (startingRow == 0 && startingCol == 0 || startingRow == 0 && startingCol == m-1
  146. || startingRow == n-1 && startingCol == 0 || startingRow == n - 1 && startingCol == m - 1)
  147. {
  148. break;
  149. }
  150. }
  151. if (direction == "sss")
  152. {
  153. break;
  154. }
  155. }
  156. /*
  157. Console.WriteLine($"row-{startingRow} and col-{startingCol}");
  158. Console.WriteLine(direction);
  159. Print(matrix);
  160. */
  161. Console.WriteLine(sum);
  162. }
  163.  
  164. static void Print(int[,] matrixToPrint)
  165. {
  166. for (int row = 0; row < matrixToPrint.GetLength(0); row++)
  167. {
  168. for (int col = 0; col < matrixToPrint.GetLength(1); col++)
  169. {
  170. Console.Write(matrixToPrint[row, col] + " ");
  171. }
  172. Console.WriteLine();
  173. }
  174. }
  175. }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement