Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Program
- {
- static void Main(string[] args)
- {
- string buffer = Console.ReadLine();
- string[] container = buffer.Split(' ');
- int n = int.Parse(container[0]);
- int m = int.Parse(container[1]);
- int jumps = int.Parse(container[2]);
- buffer = Console.ReadLine();
- container = buffer.Split(' ');
- int start_row = int.Parse(container[0]);
- int start_col = int.Parse(container[1]);
- //create the matrix
- int[,] matrix = new int[n, m];
- int counter = 1;
- List<int> numbersJumpedOn = new List<int>();
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- matrix[i, j] = counter++;
- }
- }
- //adding starting position to the arraylIst
- numbersJumpedOn.Add(matrix[start_row, start_col]);
- List<string> allJumps = new List<string>();
- for (int i = 0; i < jumps; i++)
- {
- allJumps.Add(Console.ReadLine());
- }
- int k = 0;
- while(true)
- {
- if (k > jumps-1)
- {
- k = 0;
- }
- container = allJumps[k].Split(' ');
- k++;
- int nextJum_row = int.Parse(container[0]);
- int nextJum_col = int.Parse(container[1]);
- start_row += nextJum_row;
- start_col += nextJum_col;
- if (start_row < 0 || start_col < 0 || start_row > n-1 || start_col > m-1)
- {
- Console.WriteLine("escaped {0}", Sum(numbersJumpedOn));
- break;
- }
- if (numbersJumpedOn.IndexOf(matrix[start_row, start_col]) == -1)
- {
- numbersJumpedOn.Add(matrix[start_row, start_col]);
- }
- else
- {
- Console.WriteLine("caught {0}", numbersJumpedOn.Count-1);
- break;
- }
- }
- }
- public static int Sum(List<int> baba)
- {
- int sum = 0;
- foreach (var item in baba)
- {
- sum += item;
- }
- return sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement