Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class AngryBits
- {
- static int[,] matrix = new int[8, 16];
- static int count = 0;
- static void Main()
- {
- for (int row = 0; row < 8; row++)
- {
- int bit = int.Parse(Console.ReadLine());
- for (int col = 15; col >= 0; col--)
- {
- matrix[row,col] = bit >> col & 1;
- }
- }
- for (int col = 8; col <= 15; col++)
- {
- string direction = "right";
- int currentRow = -1;
- for (int row = 0; row < 8; row++)
- {
- if (matrix[row, col] == 1)
- {
- currentRow = row;
- matrix[row, col] = 0;
- break;
- }
- }
- if (currentRow == -1)
- {
- continue;
- }
- if (currentRow == 0)
- {
- direction = "down";
- }
- int currentCount = 0;
- int currentCol = col;
- while (true)
- {
- if (direction == "right")
- {
- currentCol--;
- currentRow--;
- if (matrix[currentRow, currentCol] == 1)
- {
- currentCount = col - currentCol;
- CheckForPigs(currentRow, currentCol,currentCount);
- break;
- }
- else if (currentRow == 0)
- {
- direction = "down";
- }
- }
- if (direction == "down")
- {
- currentCol--;
- currentRow++;
- if (matrix[currentRow, currentCol] == 1)
- {
- currentCount = col - currentCol;//по формула//Path
- CheckForPigs(currentRow, currentCol, currentCount);
- break;
- }
- if (currentCol == 0 || currentRow == 7)
- {
- break;
- }
- }
- }
- }
- bool isPigsHitted = true;
- for (int row = 0; row < 8; row++)
- {
- for (int col = 0; col < 16; col++)
- {
- if (matrix[row, col] == 1)
- {
- isPigsHitted = false;
- break;
- }
- }
- }
- if (isPigsHitted)
- {
- Console.WriteLine(count + " Yes");
- }
- else
- {
- Console.WriteLine(count + " No");
- }
- }
- static void CheckForPigs(int currentRow, int currentCol,int currentCount)
- {
- int score = 0;
- for (int i = currentRow - 1; i <= currentRow + 1; i++)
- {
- for (int j = currentCol + 1; j >= currentCol - 1; j--)
- {
- if (i != -1 && i != 8 && (j != -1))
- {
- if (matrix[i, j] == 1)
- {
- score++;
- matrix[i, j] = 0;
- }
- }
- }
- }
- count += score * currentCount;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment