Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- struct Bomb
- {
- public int w;
- public int h;
- public int d;
- public int p;
- }
- struct Color
- {
- public char Name;
- public int Count;
- }
- class BombingCuboids
- {
- static char[, ,] cuboid;
- static int width, height, depth;
- static List<Bomb> bombs = new List<Bomb>();
- static List<Color> removedColors = new List<Color>();
- static int totalRemoved= 0;
- static void Main()
- {
- InputCuboid();
- InputBombs();
- for (int i = 0; i < bombs.Count; i++)
- {
- MakeBoom(bombs[i]);
- }
- removedColors.Sort((x,y) => x.Name.CompareTo(y.Name));
- Console.WriteLine(totalRemoved);
- foreach (var color in removedColors)
- {
- Console.WriteLine("{0} {1}", color.Name, color.Count);
- }
- }
- static void MakeBoom(Bomb bomb)
- {
- //Remove cubs
- for (int w = 0; w < width; w++)
- {
- for (int d = 0; d < depth; d++)
- {
- int removed = 0;
- for (int h = 0; h < height; h++)
- {
- if (cuboid[w,h,d] == '0')
- {
- continue;
- }
- double distance = Math.Sqrt((w - bomb.w) * (w - bomb.w) + (h - bomb.h) * (h - bomb.h) + (d - bomb.d) * (d - bomb.d));
- if (distance <= bomb.p)
- {
- int index = removedColors.FindIndex(a => a.Name == cuboid[w,h,d] && a.Count > 0);
- if (index>=0)
- {
- Color color = removedColors[index];
- color.Count++;
- removedColors[index] = color;
- }
- else
- {
- Color newColor = new Color();
- newColor.Name = cuboid[w, h, d];
- newColor.Count = 1;
- removedColors.Add(newColor);
- }
- cuboid[w, h, d] = '0';
- removed++;
- totalRemoved++;
- }
- }
- if (removed > 0)
- {
- FallDown(w, d, removed);
- }
- }
- }
- }
- static void FallDown(int w, int d, int removed)
- {
- int removedStart = 0;
- while (cuboid[w,removedStart,d] != '0')
- {
- removedStart++;
- }
- while (removedStart + removed < height)
- {
- cuboid[w,removedStart,d] = cuboid[w,removedStart+removed,d];
- removedStart++;
- }
- while (removedStart<height)
- {
- cuboid[w, removedStart, d] = '0';
- removedStart++;
- }
- }
- static void InputBombs()
- {
- int n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- Bomb current = new Bomb();
- string[] line = Console.ReadLine().Split(' ');
- current.w = int.Parse(line[0]);
- current.h = int.Parse(line[1]);
- current.d = int.Parse(line[2]);
- current.p = int.Parse(line[3]);
- bombs.Add(current);
- }
- }
- static void InputCuboid()
- {
- string[] dimensions = Console.ReadLine().Split(' ');
- width = int.Parse(dimensions[0]);
- height = int.Parse(dimensions[1]);
- depth = int.Parse(dimensions[2]);
- cuboid = new char[width,height,depth];
- for (int h = 0; h < height; h++)
- {
- string[] line = Console.ReadLine().Split(' ');
- for (int d = 0; d < depth; d++)
- {
- for (int w = 0; w < width; w++)
- {
- cuboid[w, h, d] = line[d][w];
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement