Advertisement
stoianpp

angrybits

Dec 4th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.18 KB | None | 0 0
  1. using System;
  2. class AngryBits
  3. {
  4.     static int[,] field = new int[8, 16];
  5.     static int result = 0;
  6.  
  7.     static void Main()
  8.     {
  9.         for (int i = 0; i < 8; i++)
  10.         {
  11.             int numberInt = Math.Abs(int.Parse(Console.ReadLine()));
  12.             ushort number = (ushort)numberInt;
  13.             for (int g = 0; g <= 15; g++)
  14.             {
  15.                 field[i, 15-g] = (1 << g & number) == 0 ? 0 : 1;
  16.             }
  17.         }
  18.  
  19.         for (int i = 7; i >= 0; i--)
  20.         {
  21.             for (int g = 0; g < 8; g++)
  22.             {
  23.                 if (field[g,i] == 1)
  24.                 {
  25.                     Shot(g, i);
  26.                     field[g,i] = 0;
  27.                     break;
  28.                 }
  29.             }
  30.         }
  31.         bool cleaned = true;
  32.         for (int i = 0; i <= 7; i++)
  33.         {
  34.             for (int g = 8; g < 16; g++)
  35.             {
  36.                 if (field [i,g] == 1) cleaned = false;
  37.             }
  38.         }
  39.         Console.WriteLine(result + " " + (cleaned?"Yes":"No"));
  40.     }
  41.  
  42.     static void Shot (int y, int x)
  43.     {
  44.         int rally = 1;
  45.         int direction = -1;
  46.         if (y == 0) direction *= -1;
  47.         y += direction;
  48.         x++;
  49.         if (field[y, x] == 1)
  50.         {
  51.             rally++;
  52.             HitPoint(1, y, x);
  53.             field[y, x] = 0;
  54.         }
  55.         while (field[y,x] != 1)
  56.         {
  57.             if (y == 0) direction *= -1;
  58.             if (y == 7 || x == 15) return;
  59.             rally++;
  60.             y += direction;
  61.             x++;
  62.             if (field[y,x] == 1)
  63.             {
  64.                 HitPoint(rally,y,x);
  65.                 return;
  66.             }
  67.         }
  68.     }
  69.  
  70.     static void HitPoint(int path, int yHit, int xHit)
  71.     {
  72.         int hittedCells = 1;
  73.         field[yHit, xHit] = 0;
  74.         if ((yHit > 0 && xHit < 15) && (field[yHit - 1, xHit + 1] == 1))
  75.         {
  76.             hittedCells++;
  77.             field[yHit - 1, xHit + 1] = 0;
  78.         }
  79.         if (yHit > 0)
  80.         {
  81.             if (field[yHit - 1, xHit - 1] == 1)
  82.             {
  83.                 hittedCells++;
  84.                 field[yHit - 1, xHit - 1] = 0;
  85.             }
  86.             if (field[yHit - 1, xHit] == 1)
  87.             {
  88.                 hittedCells++;
  89.                 field[yHit - 1, xHit] = 0;
  90.             }
  91.         }
  92.         if (xHit < 15)
  93.         {
  94.             if (field[yHit, xHit + 1] == 1)
  95.             {
  96.                 hittedCells++;
  97.                 field[yHit, xHit + 1] = 0;
  98.             }
  99.         }
  100.         if ((yHit < 7 && xHit < 15) && (field[yHit + 1, xHit + 1] == 1))
  101.         {
  102.             hittedCells++;
  103.             field[yHit + 1, xHit + 1] = 0;
  104.         }
  105.         if (yHit < 7)
  106.         {
  107.             if (field[yHit +1 , xHit - 1] == 1)
  108.             {
  109.                 hittedCells++;
  110.                 field[yHit + 1, xHit - 1] = 0;
  111.             }
  112.             if (field[yHit + 1, xHit] == 1)
  113.             {
  114.                 hittedCells++;
  115.                 field[yHit + 1, xHit] = 0;
  116.             }
  117.         }
  118.         if (field[yHit, xHit - 1] == 1)
  119.         {
  120.             hittedCells++;
  121.             field[yHit, xHit - 1] = 0;
  122.         }
  123.         result += hittedCells * path;
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement