Advertisement
Guest User

Pesho&2-Avtorsko

a guest
Mar 12th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.31 KB | None | 0 0
  1. using System;
  2. using System.Data.SqlTypes;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Numerics;
  6. using System.Xml;
  7.  
  8. namespace LoverOf2
  9. {
  10.     internal class LoverOf2Solution
  11.     {
  12.         private static int rows;
  13.         private static int cols;
  14.         private static int coef;
  15.  
  16.         static void Main()
  17.         {
  18.             Solve();
  19.             //            string inputFileFormat = "..//..//tests//test.{0:000}.in.txt";
  20.             //            string outputFileFormat = "..//..//tests//test.{0:000}.out.txt";
  21.             //
  22.             //            for (int i = 0; i < 20; i++)
  23.             //            {
  24.             //                string inputFile = string.Format(inputFileFormat, i + 1);
  25.             //                string outputFile = string.Format(outputFileFormat, i + 1);
  26.             //                using (StreamReader reader = new StreamReader(inputFile))
  27.             //                using (StreamWriter writer = new StreamWriter(outputFile))
  28.             //                {
  29.             //                    Console.SetIn(reader);
  30.             //                    Console.SetOut(writer);
  31.             //                    Solve();
  32.             //                }
  33.             //            }
  34.         }
  35.  
  36.         private static void Solve()
  37.         {
  38.             rows = int.Parse(Console.ReadLine());
  39.             cols = int.Parse(Console.ReadLine());
  40.             coef = Math.Max(rows, cols);
  41.             int n = int.Parse(Console.ReadLine());
  42.             var moves = Console.ReadLine()
  43.                 .Split(' ')
  44.                 .Select(int.Parse)
  45.                 .ToArray();
  46.  
  47.             int row = rows - 1;
  48.             int col = 0;
  49.  
  50.             bool[,] used = new bool[rows, cols];
  51.             foreach (int move in moves)
  52.             {
  53.                 int toRow = move / coef;
  54.                 int toCol = move % coef;
  55.  
  56.                 while (row != toRow)
  57.                 {
  58.                     used[row, col] = true;
  59.                     //                    Console.WriteLine("({0}, {1})", row, col);
  60.                     if (row < toRow)
  61.                     {
  62.                         row++;
  63.                     }
  64.                     else
  65.                     {
  66.                         row--;
  67.                     }
  68.                 }
  69.                 while (col != toCol)
  70.                 {
  71.                     used[row, col] = true;
  72.                     //                    Console.WriteLine("({0}, {1})", row, col);
  73.                     if (col < toCol)
  74.                     {
  75.                         col++;
  76.                     }
  77.                     else
  78.                     {
  79.                         col--;
  80.                     }
  81.                 }
  82.                 used[row, col] = true;
  83.             }
  84.             BigInteger sum = 0;
  85.  
  86.             for (int r = 0; r < used.GetLength(0); r++)
  87.             {
  88.                 for (int c = 0; c < used.GetLength(1); c++)
  89.                 {
  90.                     if (used[r, c])
  91.                     {
  92.                         sum += GetValue(r, c, rows);
  93.                     }
  94.                 }
  95.             }
  96.             Console.WriteLine(sum);
  97.         }
  98.  
  99.         private static BigInteger GetValue(int row, int col, int rows)
  100.         {
  101.             return ((BigInteger)1) << (rows - row - 1 + col);
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement