예제 #1
0
        static void Main()
        {
            FillCube();
            int numberOfBombs = int.Parse(Console.ReadLine());
            int allDestoyed = 0;

            for (int i = 0; i < numberOfBombs; i++)
            {
                Bomb currentBomb = new Bomb();
                int[] bombInfo = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
                currentBomb.width = bombInfo[0];
                currentBomb.height = bombInfo[1];
                currentBomb.depth = bombInfo[2];
                currentBomb.power = bombInfo[3];
                bool[,] hasDestoyed = new bool[width, depth];

                for (int w = 0; w < width; w++)
                {
                    for (int h = 0; h < height; h++)
                    {
                        for (int d = 0; d < depth; d++)
                        {
                            double distance = CalculateDistance(w, h, d, currentBomb.width, currentBomb.height, currentBomb.depth);
                            if (cube[w, h, d] == '\0')
                                break;
                            if (distance <= (double)currentBomb.power)
                            {
                                char color = cube[w, h, d];
                                hasDestoyed[w, d] = true;
                                cube[w, h, d] = '\0';
                                allDestoyed++;

                                if (!bombedCollors.ContainsKey(color))
                                {
                                    bombedCollors.Add(color, 1);
                                }
                                else
                                {
                                    bombedCollors[color]++;
                                }

                            }

                        }
                    }
                }

                for (int w = 0; w < width; w++)
                {
                    for (int d = 0; d < depth; d++)
                    {
                        if (!hasDestoyed[w, d])
                            continue;
                        int holes = 0;

                        for (int h = 0; h < height; h++)
                        {
                            if (cube[w, h, d] == '\0')
                            {
                                holes++;
                            }
                            else
                            {
                                if (holes != 0)
                                {
                                    cube[w, h - holes, d] = cube[w, h, d];
                                    cube[w, h, d] = '\0';
                                }
                            }
                        }
                    }
                }

            }
            var list = bombedCollors.Keys.ToList();
            list.Sort();

            Console.WriteLine(allDestoyed);
            foreach (var item in list)
            {
                Console.WriteLine("{0} {1}",item, bombedCollors[item]);
            }
        }
예제 #2
0
        static void Main()
        {
            FillCube();
            int numberOfBombs = int.Parse(Console.ReadLine());
            int allDestoyed   = 0;

            for (int i = 0; i < numberOfBombs; i++)
            {
                Bomb  currentBomb = new Bomb();
                int[] bombInfo    = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
                currentBomb.width   = bombInfo[0];
                currentBomb.height  = bombInfo[1];
                currentBomb.depth   = bombInfo[2];
                currentBomb.power   = bombInfo[3];
                bool[,] hasDestoyed = new bool[width, depth];

                for (int w = 0; w < width; w++)
                {
                    for (int h = 0; h < height; h++)
                    {
                        for (int d = 0; d < depth; d++)
                        {
                            double distance = CalculateDistance(w, h, d, currentBomb.width, currentBomb.height, currentBomb.depth);
                            if (cube[w, h, d] == '\0')
                            {
                                break;
                            }
                            if (distance <= (double)currentBomb.power)
                            {
                                char color = cube[w, h, d];
                                hasDestoyed[w, d] = true;
                                cube[w, h, d]     = '\0';
                                allDestoyed++;

                                if (!bombedCollors.ContainsKey(color))
                                {
                                    bombedCollors.Add(color, 1);
                                }
                                else
                                {
                                    bombedCollors[color]++;
                                }
                            }
                        }
                    }
                }

                for (int w = 0; w < width; w++)
                {
                    for (int d = 0; d < depth; d++)
                    {
                        if (!hasDestoyed[w, d])
                        {
                            continue;
                        }
                        int holes = 0;

                        for (int h = 0; h < height; h++)
                        {
                            if (cube[w, h, d] == '\0')
                            {
                                holes++;
                            }
                            else
                            {
                                if (holes != 0)
                                {
                                    cube[w, h - holes, d] = cube[w, h, d];
                                    cube[w, h, d]         = '\0';
                                }
                            }
                        }
                    }
                }
            }
            var list = bombedCollors.Keys.ToList();

            list.Sort();

            Console.WriteLine(allDestoyed);
            foreach (var item in list)
            {
                Console.WriteLine("{0} {1}", item, bombedCollors[item]);
            }
        }