Advertisement
Teodor92

Angry Bits

Dec 29th, 2012
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.83 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. class ProblemFive
  7. {
  8.     static void Main()
  9.     {
  10.         //input
  11.         int[,] matrix = new int[8, 16];
  12.         for (int row = 0; row < 8; row++)
  13.         {
  14.             int input = int.Parse(Console.ReadLine());
  15.             for (int col = 0; col < 16; col++)
  16.             {
  17.                 matrix[row, col] = input % 2;
  18.                 input = input / 2;
  19.             }
  20.         }
  21.         // main logic
  22.         // bird finder
  23.         int score = 0;
  24.         int flightLen = 0;
  25.         int birdNum = 0;
  26.         int deadPigs = 0;
  27.         for (int birdCol = 8; birdCol < 16; birdCol++)
  28.         {
  29.             for (int birdRow = 0; birdRow < 8; birdRow++)
  30.             {
  31.  
  32.                 if (matrix[birdRow, birdCol] == 1)
  33.                 {
  34.                     int defCol = birdCol;
  35.                     int defRow = birdRow;
  36.                     int dirRow = -1;
  37.                     int dirCol = -1;
  38.                     bool isDead = false;
  39.                     while (isDead == false)
  40.                     {
  41.  
  42.                         if (birdRow == 0)
  43.                         {
  44.                             dirRow = 1;
  45.                         }
  46.                         birdRow = birdRow + dirRow;
  47.                         birdCol = birdCol + dirCol;
  48.                         if (birdRow > 7 || birdCol < 0)
  49.                         {
  50.                             isDead = true;
  51.                             break;
  52.                         }
  53.                         if (birdCol < 8 && matrix[birdRow, birdCol] == 1)
  54.                         {
  55.                             deadPigs++;
  56.                             // 0 0 0
  57.                             // 1 0 0
  58.                             // 0 0 0
  59.                             if (birdCol + 1 != 8)
  60.                             {
  61.                                 if (matrix[birdRow, birdCol + 1] == 1)
  62.                                 {
  63.                                     deadPigs++;
  64.                                     matrix[birdRow, birdCol + 1] = 0;
  65.                                 }
  66.                             }
  67.                             // 0 0 0
  68.                             // 0 0 0
  69.                             // 1 0 0
  70.                             if (birdRow < 7 && birdCol + 1 != 8)
  71.                             {
  72.                                 if (matrix[birdRow + 1, birdCol + 1] == 1)
  73.                                 {
  74.                                     deadPigs++;
  75.                                     matrix[birdRow + 1, birdCol + 1] = 0;
  76.                                 }
  77.  
  78.                             }
  79.                             // 0 0 0
  80.                             // 0 0 0
  81.                             // 0 1 0
  82.                             if (birdRow < 7)
  83.                             {
  84.                                 if (matrix[birdRow + 1, birdCol] == 1)
  85.                                 {
  86.                                     deadPigs++;
  87.                                     matrix[birdRow + 1, birdCol] = 0;
  88.                                 }
  89.                             }
  90.                             // 1 0 0
  91.                             // 0 0 0
  92.                             // 0 0 0
  93.                             if (birdRow > 0 && birdCol + 1 != 8)
  94.                             {
  95.                                 if (matrix[birdRow - 1, birdCol + 1] == 1)
  96.                                 {
  97.                                     deadPigs++;
  98.                                     matrix[birdRow - 1, birdCol + 1] = 0;
  99.                                 }
  100.                             }
  101.                             // 0 1 0
  102.                             // 0 0 0
  103.                             // 0 0 0
  104.                             if (birdRow > 0)
  105.                             {
  106.                                 if (matrix[birdRow - 1, birdCol] == 1)
  107.                                 {
  108.                                     deadPigs++;
  109.                                     matrix[birdRow - 1, birdCol] = 0;
  110.                                 }
  111.                             }
  112.                             // 0 0 1
  113.                             // 0 0 0
  114.                             // 0 0 0
  115.                             if (birdRow > 0 && birdCol > 0)
  116.                             {
  117.                                 if (matrix[birdRow - 1, birdCol - 1] == 1)
  118.                                 {
  119.                                     deadPigs++;
  120.                                     matrix[birdRow - 1, birdCol - 1] = 0;
  121.                                 }
  122.  
  123.                             }
  124.                             // 0 0 0
  125.                             // 0 0 1
  126.                             // 0 0 0
  127.                             if (birdCol > 0)
  128.                             {
  129.                                 if (matrix[birdRow, birdCol - 1] == 1)
  130.                                 {
  131.                                     deadPigs++;
  132.                                     matrix[birdRow, birdCol - 1] = 0;
  133.                                 }
  134.  
  135.                             }
  136.                             // 0 0 0
  137.                             // 0 0 0
  138.                             // 0 0 1
  139.                             if (birdCol > 0 && birdRow < 7)
  140.                             {
  141.                                 if (matrix[birdRow + 1, birdCol - 1] == 1)
  142.                                 {
  143.                                     deadPigs++;
  144.                                     matrix[birdRow + 1, birdCol - 1] = 0;
  145.                                 }
  146.                             }
  147.                             isDead = true;
  148.                             matrix[birdRow, birdCol] = 0;
  149.                         }
  150.  
  151.                         flightLen++;
  152.                     }
  153.                     birdRow = defRow;
  154.                     birdCol = defCol;
  155.                 }
  156.                 score = score + flightLen * deadPigs;
  157.                 flightLen = 0;
  158.                 deadPigs = 0;
  159.             }
  160.         }
  161.         // alive checker
  162.         bool areAlive = false;
  163.         for (int birdRow = 0; birdRow < 8; birdRow++)
  164.         {
  165.             for (int birdCol = 0; birdCol < 8; birdCol++)
  166.             {
  167.                 if (matrix[birdRow, birdCol] == 1)
  168.                 {
  169.                     areAlive = true;
  170.                     break;
  171.                 }
  172.             }
  173.         }
  174.         //testing
  175.         //for (int i = 0; i < matrix.GetLength(0); i++)
  176.         //{
  177.         //    for (int j = 0; j < matrix.GetLength(1); j++)
  178.         //    {
  179.         //        Console.Write("{0}", matrix[i, j]);
  180.         //    }
  181.         //    Console.WriteLine();
  182.         //}
  183.         Console.Write("{0} ", score);
  184.         if (areAlive)
  185.         {
  186.             Console.WriteLine("No");
  187.         }
  188.         else
  189.         {
  190.             Console.WriteLine("Yes");
  191.         }
  192.  
  193.  
  194.     }
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement