Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Program
- {
- static Dictionary<char, int> blowLetters = new Dictionary<char, int>();
- static int count;
- static void Main()
- {
- int width; // x
- int height; // y
- int depth; // z
- string[] input = Console.ReadLine().Split();
- width = int.Parse(input[0]);
- height = int.Parse(input[1]);
- depth = int.Parse(input[2]);
- char[, ,] cube = new char[width, height, depth];
- //bool[, ,] visited = new bool[width, height, depth];
- string[] rows = new string[height]; // y
- string[] columns = new string[depth]; // z
- string cells = string.Empty; // x
- for (int y = 0; y < height; y++)
- {
- rows[y] = Console.ReadLine();
- //rows[0] = "AAAA AAAA AAAA AAAA AAAA";
- //rows[1] = "AAAA AAAA AAAA AAAA AAAC";
- //rows[2] = "ABAA AAAA AAAA AAAA AAAA";
- for (int z = 0; z < depth; z++)
- {
- columns = rows[y].Split(new string[] { " " }, StringSplitOptions.None);
- cells = columns[z];
- for (int x = 0; x < width; x++)
- {
- cube[x, y, z] = cells[x];
- }
- }
- }
- List<Bombs> bomb = new List<Bombs>();
- int numOfBombs = int.Parse(Console.ReadLine());
- string[] bombDetails = new string[numOfBombs];
- for (int i = 0; i < numOfBombs; i++)
- {
- bombDetails = Console.ReadLine().Split();
- bomb.Add(new Bombs(int.Parse(bombDetails[0]), int.Parse(bombDetails[1]), int.Parse(bombDetails[2]), int.Parse(bombDetails[3])));
- }
- for (int i = 0; i < bomb.Count; i++)
- {
- BlowBomb(bomb[i], cube, width, height, depth);
- FallDown(bomb[i], cube, width, height, depth);
- }
- //PrintCube(cube);
- Console.WriteLine(count);
- var sorted = blowLetters.OrderBy(x => x.Key);
- foreach (var item in sorted)
- {
- Console.WriteLine(item.Key + " " + item.Value);
- }
- }
- private static void FallDown(Bombs currentBomb, char[, ,] cube,int width,int height,int depth)
- {
- //current bomb height
- Point currentPoint = new Point(currentBomb.x, currentBomb.y, currentBomb.z);
- FallDownColumn(currentPoint, cube);
- int startDepth = Math.Max(currentBomb.z - currentBomb.power, 0);
- int endDepth = Math.Min(currentBomb.z + currentBomb.power + 1, depth);
- int startWidth = Math.Max(currentBomb.x - currentBomb.power, 0);
- int endWidth = Math.Min(currentBomb.x + currentBomb.power + 1, width);
- for (int z = startDepth; z < endDepth; z++)
- {
- for (int x = startWidth; x < endWidth; x++)
- {
- currentPoint.x = x;
- currentPoint.z = z;
- FallDownColumn(currentPoint, cube);
- }
- }
- ////x +
- //for (int i = currentBomb.x + 1; i < cube.GetLength(0) && i <= (currentBomb.x + currentBomb.power + 1); i++)
- //{
- // currentPoint.z = currentBomb.z;
- // currentPoint.x = i;
- // FallDownColumn(currentPoint, cube);
- //}
- //// x-
- //for (int i = currentBomb.x - 1; i >= 0 && i >= (currentBomb.x - currentBomb.power - 1); i--)
- //{
- // currentPoint.z = currentBomb.z;
- // currentPoint.x = i;
- // FallDownColumn(currentPoint, cube);
- //}
- //// z+
- //for (int i = currentBomb.z + 1; i < cube.GetLength(2) && i <= (currentBomb.z + currentBomb.power + 1); i++)
- //{
- // currentPoint.x = currentBomb.x;
- // currentPoint.z = i;
- // FallDownColumn(currentPoint, cube);
- //}
- //// z-
- //for (int i = currentBomb.z - 1; i >= 0 && i >= (currentBomb.z - currentBomb.power - 1); i--)
- //{
- // currentPoint.x = currentBomb.x;
- // currentPoint.z = i;
- // FallDownColumn(currentPoint, cube);
- //}
- }
- private static void FallDownColumn(Point currentPoint, char[, ,] cube)
- {
- for (int pos = 0; pos < cube.GetLength(1); pos++)
- {
- if (cube[currentPoint.x, pos, currentPoint.z] == '*')
- {
- Point empty = new Point(currentPoint.x, pos, currentPoint.z);
- Swap(empty, cube);
- }
- }
- }
- private static void Swap(Point empty, char[, ,] cube)
- {
- for (int pos = empty.y + 1; pos < cube.GetLength(1); pos++)
- {
- if (cube[empty.x, pos, empty.z] != '*')
- {
- cube[empty.x, empty.y, empty.z] = cube[empty.x, pos, empty.z];
- cube[empty.x, pos, empty.z] = '*';
- return;
- }
- }
- }
- private static void BlowBomb(Bombs currentBomb, char[, ,] cube, int width, int height, int depth)
- {
- Point currentPoint = new Point(currentBomb.x, currentBomb.y, currentBomb.z);
- BlowCube(cube, currentPoint);
- int startDepth = Math.Max(currentBomb.z - currentBomb.power, 0);
- int endDepth = Math.Min(currentBomb.z + currentBomb.power + 1, depth);
- int startHeight = Math.Max(currentBomb.y - currentBomb.power, 0);
- int endHeight = Math.Min(currentBomb.y + currentBomb.power + 1, height);
- int startWidth = Math.Max(currentBomb.x - currentBomb.power, 0);
- int endWidth = Math.Min(currentBomb.x + currentBomb.power + 1, width);
- for (int y = startHeight; y < endHeight; y++)
- {
- for (int z = startDepth; z < endDepth; z++)
- {
- for (int x = startWidth; x < endWidth; x++)
- {
- currentPoint.x = x;
- currentPoint.y = y;
- currentPoint.z = z;
- if (CheckDistance(currentPoint, currentBomb))
- {
- BlowCube(cube, currentPoint);
- }
- }
- }
- }
- // x +
- // for (int x = currentBomb.x + 1 ; x < cube.GetLength(0) && x <= (currentBomb.x + currentBomb.power); x++)
- // {
- // currentPoint.x = x;
- // currentPoint.y = currentBomb.y;
- // currentPoint.z = currentBomb.z;
- // if (CheckDistance(currentPoint, currentBomb))
- // {
- // BlowCube(cube, currentPoint);
- // }
- // }
- // // x -
- // for (int x = currentBomb.x -1 ; x >= 0 && x >= (currentBomb.x - currentBomb.power); x--)
- // {
- // currentPoint.x = x;
- // currentPoint.y = currentBomb.y;
- // currentPoint.z = currentBomb.z;
- // if (CheckDistance(currentPoint, currentBomb))
- // {
- // BlowCube(cube, currentPoint);
- // }
- // }
- // // y +
- // for (int y = currentBomb.y +1 ; y < cube.GetLength(1) && y <= (currentBomb.y + currentBomb.power); y++)
- // {
- // currentPoint.x = currentBomb.x;
- // currentPoint.y = y;
- // currentPoint.z = currentBomb.z;
- // if (CheckDistance(currentPoint, currentBomb))
- // {
- // BlowCube(cube, currentPoint);
- // }
- // }
- // // y -
- // for (int y = currentBomb.y -1 ; y >= 0 && y >= (currentBomb.y - currentBomb.power); y--)
- // {
- // currentPoint.x = currentBomb.x;
- // currentPoint.y = y;
- // currentPoint.z = currentBomb.z;
- // if (CheckDistance(currentPoint, currentBomb))
- // {
- // BlowCube(cube, currentPoint);
- // }
- // }
- // // z +
- // for (int z = currentBomb.z +1; z < cube.GetLength(2) && z <= (currentBomb.z + currentBomb.power); z++)
- // {
- // currentPoint.x = currentBomb.x;
- // currentPoint.y = currentBomb.y;
- // currentPoint.z = z;
- // if (CheckDistance(currentPoint, currentBomb))
- // {
- // BlowCube(cube, currentPoint);
- // }
- // }
- // // z -
- // for (int z = currentBomb.z -1; z >= 0 && z >= (currentBomb.z - currentBomb.power); z--)
- // {
- // currentPoint.x = currentBomb.x;
- // currentPoint.y = currentBomb.y;
- // currentPoint.z = z;
- // if (CheckDistance(currentPoint, currentBomb))
- // {
- // BlowCube(cube, currentPoint);
- // }
- // }
- }
- private static void BlowCube(char[, ,] cube, Point currentPoint)
- {
- char currentCubeChar = cube[currentPoint.x, currentPoint.y, currentPoint.z];
- if (currentCubeChar == '*')
- {
- return;
- }
- if (blowLetters.ContainsKey(currentCubeChar))
- {
- blowLetters[currentCubeChar]++;
- count++;
- }
- else
- {
- blowLetters.Add(currentCubeChar, 1);
- count++;
- }
- cube[currentPoint.x, currentPoint.y, currentPoint.z] = '*'; //mark
- }
- private static bool CheckDistance(Point currentPoint, Bombs currentBomb)
- {
- double result;
- result = (currentPoint.x - currentBomb.x) * (currentPoint.x - currentBomb.x) +
- (currentPoint.y - currentBomb.y) * (currentPoint.y - currentBomb.y) +
- (currentPoint.z - currentBomb.z) * (currentPoint.z - currentBomb.z);
- if (result <= currentBomb.power * currentBomb.power)
- {
- return true; // boom
- }
- else
- {
- return false; // no boom
- }
- }
- private static void PrintCube(char[, ,] cube)
- {
- for (int y = 0; y < cube.GetLength(1); y++)
- {
- for (int z = 0; z < cube.GetLength(2); z++)
- {
- for (int x = 0; x < cube.GetLength(0); x++)
- {
- Console.Write(cube[x, y, z]);
- }
- Console.Write(" ");
- }
- Console.WriteLine();
- }
- }
- }
- class Bombs
- {
- public int x;
- public int y;
- public int z;
- public int power;
- public Bombs(int x, int y, int z, int power)
- {
- this.x = x;
- this.y = y;
- this.z = z;
- this.power = power;
- }
- }
- class Point
- {
- public int x;
- public int y;
- public int z;
- public Point(int x, int y, int z)
- {
- this.x = x;
- this.y = y;
- this.z = z;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment