psotirov

Angry Bits

Dec 29th, 2012
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. class AngryBirds
  7. {
  8.     static void Main()
  9.     {
  10.         int[,] field = new int[8, 16];
  11.         int[] birdsPos = {-1, -1, -1, -1, -1, -1, -1, -1};
  12.         int pigsNr = 0;
  13.         int score = 0;
  14.  
  15.         for (int i = 0; i < 8; i++)
  16.         {
  17.             int line = int.Parse(Console.ReadLine());
  18.             for (int j = 0; j < 16; j++)
  19.             {
  20.                 if (((line >> j) & 1) == 1)
  21.                 {
  22.                     if (j > 7) birdsPos[j - 8] = i;
  23.                     else
  24.                     {
  25.                         pigsNr++;
  26.                         field[i, j] = 1;
  27.                     }
  28.                 }
  29.             }
  30.         }
  31.  
  32.         for (int i = 0; i < 8; i++)
  33.         {
  34.             if (birdsPos[i] >= 0)
  35.             {
  36.                 int distance = 0;
  37.                 int posX = i + 8;
  38.                 int posY = birdsPos[i];
  39.                 int direction = -1;
  40.                 if (posY == 0) direction = 1;
  41.                 bool hasFinished = false;
  42.                 while (!hasFinished)
  43.                 {
  44.                     posX--;
  45.                     posY += direction;
  46.                     if (posX == 0 || posY == 7) hasFinished = true;
  47.                     if (posY == 0) direction = 1;
  48.                     distance++;
  49.                     if (field[posY, posX] > 0) //impact
  50.                     {
  51.                         int pigsCount = 0;
  52.                         for (int y = posY-1; y < posY+2; y++)
  53.                             for (int x = posX-1; x < posX+2; x++)
  54.                             {
  55.                                 if (x < 0 || x > 7 || y < 0 || y > 7) continue;
  56.                                 if (field[y, x] > 0)
  57.                                 {
  58.                                     field[y, x] = 0;
  59.                                     pigsCount++;
  60.                                 }
  61.                             }
  62.                         score += distance * pigsCount;
  63.                         pigsNr -= pigsCount;
  64.                         hasFinished = true;
  65.                     }
  66.                 }
  67.             }
  68.         }
  69.  
  70.         Console.WriteLine("{0} {1}", score, (pigsNr > 0)?"No":"Yes");
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment