Example #1
0
        static void Main()
        {
            const int MAX_VOLUME = 10;

            Cups        cups, cups2;
            InputReader reader = new InputReader();

            int[] optimal = new int[MAX_VOLUME + 1];
            for (int i = 0; i <= MAX_VOLUME; i++)
            {
                optimal[i] = -1;
            }

            int[,,] moves = new int[MAX_VOLUME + 1, MAX_VOLUME + 1, MAX_VOLUME + 1];
            for (int i = 0; i <= MAX_VOLUME; i++)
            {
                for (int j = 0; j <= MAX_VOLUME; j++)
                {
                    for (int k = 0; k <= MAX_VOLUME; k++)
                    {
                        moves[i, j, k] = -1;
                    }
                }
            }

            cups = new Cups(
                reader.ReadInt(), reader.ReadInt(), reader.ReadInt(), // Capacity
                reader.ReadInt(), reader.ReadInt(), reader.ReadInt()  // Volume
                );

            moves[cups.Volume[0], cups.Volume[1], cups.Volume[2]] = 0;

            for (int i = 0; i < 3; i++)
            {
                optimal[cups.Volume[i]] = 0;
            }

            Queue <Cups> queue = new Queue <Cups>();

            queue.Enqueue(cups);
            while (queue.CanDequeue)
            {
                cups = queue.Dequeue();
                int move = moves[cups.Volume[0], cups.Volume[1], cups.Volume[2]];

                // Console.WriteLine(cups.ToString());

                for (int from = 0; from < 3; from++)
                {
                    for (int to = 0; to < 3; to++)
                    {
                        if (from != to)
                        {
                            cups2 = Cups.Copy(cups).Swap(from, to);

                            if (moves[cups2.Volume[0], cups2.Volume[1], cups2.Volume[2]] == -1)
                            {
                                moves[cups2.Volume[0], cups2.Volume[1], cups2.Volume[2]] = move + 1;

                                for (int i = 0; i < 3; i++)
                                {
                                    if (optimal[cups2.Volume[i]] == -1)
                                    {
                                        optimal[cups2.Volume[i]] = move + 1;
                                    }
                                }

                                queue.Enqueue(cups2);
                            }
                        }
                    }
                }
            }

            for (int i = 0; i <= MAX_VOLUME; i++)
            {
                if (optimal[i] > -1)
                {
                    Console.Write("{0}:{1} ", i, optimal[i]);
                }
            }

            Console.WriteLine();
        }