Advertisement
Guest User

Pesho&2

a guest
Mar 12th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _03
  8. {
  9.     class Program
  10.     {
  11.  
  12.         static void Main(string[] args)
  13.         {
  14.             int r = int.Parse(Console.ReadLine());
  15.             int c = int.Parse(Console.ReadLine());
  16.             int n = int.Parse(Console.ReadLine());
  17.             decimal[] commands = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => decimal.Parse(x)).ToArray();
  18.             BigInteger sum = 0;
  19.             BigInteger[,] matrix = new BigInteger[r, c];
  20.             BigInteger power = 1;
  21.             for (int row = r - 1; row >= 0; row--)
  22.             {
  23.                 for (int col = 0; col < c; col++)
  24.                 {
  25.                     matrix[row, col] = (BigInteger)((BigInteger)Math.Pow(2, col) * power);
  26.                 }
  27.                 power = power * 2;
  28.             }
  29.             int peshoRow = r - 1;
  30.             int peshoCol = 0;
  31.  
  32.             string direction = "";
  33.             switch (direction)
  34.             {
  35.                 case "up": peshoRow--;
  36.                     break;
  37.                 case "down": peshoRow++;
  38.                     break;
  39.                 case "left": peshoCol--;
  40.                     break;
  41.                 case "right": peshoCol++;
  42.                     break;
  43.             }
  44.  
  45.             foreach (var command in commands)
  46.             {
  47.                 int coeff = Math.Max(r, c);
  48.                 decimal targetRow = (ulong)(command / coeff);
  49.                 decimal targetCol = (ulong)(command % coeff);
  50.  
  51.                 while (targetRow != peshoRow && peshoRow >= 0 && peshoRow < r && peshoCol < c && peshoCol >= 0)
  52.                 {
  53.                     if (targetRow < peshoRow) peshoRow--;//direction = "up";
  54.                     else if (targetRow > peshoRow) peshoRow++;//direction = "down";
  55.                     sum += matrix[peshoRow, peshoCol];
  56.                     matrix[peshoRow, peshoCol] = 0;
  57.  
  58.                 }
  59.                 while (targetCol != peshoCol && peshoRow >= 0 && peshoRow < r && peshoCol < c && peshoCol >= 0)
  60.                 {
  61.                     if (targetCol < peshoCol) peshoCol--;
  62.                     else if (targetCol > peshoCol) peshoCol++;
  63.                     sum += matrix[peshoRow, peshoCol];
  64.                     matrix[peshoRow, peshoCol] = 0;
  65.                 }
  66.             }
  67.  
  68.             Console.WriteLine(sum + 1);
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement