Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class AngryBits
- {
- static int[,] field = new int[8, 16];
- static int result = 0;
- static void Main()
- {
- for (int i = 0; i < 8; i++)
- {
- int numberInt = Math.Abs(int.Parse(Console.ReadLine()));
- ushort number = (ushort)numberInt;
- for (int g = 0; g <= 15; g++)
- {
- field[i, 15-g] = (1 << g & number) == 0 ? 0 : 1;
- }
- }
- for (int i = 7; i >= 0; i--)
- {
- for (int g = 0; g < 8; g++)
- {
- if (field[i,g] == 1)
- {
- Shot(i, g);
- field[i,g] = 0;
- break;
- }
- }
- }
- bool cleaned = true;
- for (int i = 0; i <= 7; i++)
- {
- for (int g = 8; g < 16; g++)
- {
- if (field [i,g] == 1) cleaned = false;
- }
- }
- Console.WriteLine(result + " " + (cleaned?"Yes":"No"));
- }
- static void Shot (int y, int x)
- {
- int rally = 1;
- int direction = -1;
- if (y == 0) direction *= -1;
- y += direction;
- x++;
- if (field[y, x] == 1)
- {
- rally++;
- HitPoint(1, y, x);
- field[y, x] = 0;
- }
- while (field[y,x] != 1)
- {
- if (y == 0) direction *= -1;
- if (y == 7 || x == 15) return;
- rally++;
- y += direction;
- x++;
- if (field[y,x] == 1)
- {
- HitPoint(rally,y,x);
- return;
- }
- }
- }
- static void HitPoint(int path, int yHit, int xHit)
- {
- int hittedCells = 1;
- field[yHit, xHit] = 0;
- if ((yHit > 0 && xHit < 15) && (field[yHit - 1, xHit + 1] == 1))
- {
- hittedCells++;
- field[yHit - 1, xHit + 1] = 0;
- }
- if (yHit > 0)
- {
- if (field[yHit - 1, xHit - 1] == 1)
- {
- hittedCells++;
- field[yHit - 1, xHit - 1] = 0;
- }
- if (field[yHit - 1, xHit] == 1)
- {
- hittedCells++;
- field[yHit - 1, xHit] = 0;
- }
- }
- if (xHit < 15)
- {
- if (field[yHit, xHit + 1] == 1)
- {
- hittedCells++;
- field[yHit, xHit + 1] = 0;
- }
- }
- if ((yHit < 7 && xHit < 15) && (field[yHit + 1, xHit + 1] == 1))
- {
- hittedCells++;
- field[yHit + 1, xHit + 1] = 0;
- }
- if (yHit < 7)
- {
- if (field[yHit +1 , xHit - 1] == 1)
- {
- hittedCells++;
- field[yHit + 1, xHit - 1] = 0;
- }
- if (field[yHit + 1, xHit] == 1)
- {
- hittedCells++;
- field[yHit + 1, xHit] = 0;
- }
- }
- if (field[yHit, xHit - 1] == 1)
- {
- hittedCells++;
- field[yHit, xHit - 1] = 0;
- }
- result += hittedCells * path;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement