示例#1
0
        static void Main(string[] args)
        {
            // create objects
            FileReader fr = new FileReader();

            // read list of commands
            List<List<int>> commands = fr.getCommands("input.txt");

            // prepare list of results
            List<int[]> results = new List<int[]>();

            // prepare list of couriers
            List<FibHeap> couriers = new List<FibHeap>();

            /*
             * loop thru commands
             *
             * commands are "documented" in FileReader.cs
             *
             */
            foreach (List<int> command in commands)
            {
                if (command[0] == 1)
                {
                    Console.WriteLine("Adding courier " + command[1]);
                    connections.Add(command[1]);
                    couriers.Add(new FibHeap());
                }
                if (command[0] == 2)
                {
                    Console.WriteLine("Adding to courier " + command[1] + " package id: " + command[2] + " prio: " + command[3]);
                    couriers[findSlot(command[1])].Insert(command[3]);
                }
                if (command[0] == 3)
                {
                    Console.WriteLine("Showing courier " + command[1] + " first package");

                        int package = couriers[findSlot(command[1])].ExtractMax();

                        int[] result = new int[2];
                        result[0] = command[1];
                        result[1] = package;

                        results.Add(result);
                }
                if (command[0] == 4)
                {
                    Console.WriteLine("Move packages from couirer " + command[1] + " to courier " + command[2]);
                    couriers[findSlot(command[1])].Union(couriers[findSlot(command[2])]);
                    couriers[findSlot(command[2])] = new FibHeap();
                }
            }

            // print results
            fr.printResults("output.txt", results);

            //Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            // create objects
            PriorityQueue<int> pq = new PriorityQueue<int>();
            FileReader fr = new FileReader();

            // read list of commands
            List<List<int>> commands = fr.getCommands("input.txt");

            // prepare list of results
            List<int[]> results = new List<int[]>();

            // prepare list of couriers
            List<PriorityQueue<int>> couriers= new List<PriorityQueue<int>>();

            /*
             * loop thru commands
             *
             * commands are "documented" in FileReader.cs
             *
             */
            foreach (List<int> command in commands)
            {
                if (command[0] == 1)
                {
                    Console.WriteLine("Adding courier " + command[1]);
                    connections.Add(command[1]);
                    couriers.Add(new PriorityQueue<int>());
                }
                if (command[0] == 2)
                {
                    Console.WriteLine("Adding to courier " + command[1] + " package id: " + command[2] + " prio: " + command[3]);
                    couriers[findSlot(command[1])].Enqueue(command[2], command[3]);
                }
                if (command[0] == 3)
                {
                    Console.WriteLine("Showing courier " + command[1] + " first package");
                    if (!couriers[findSlot(command[1])].Empty)
                    {
                        int prio = couriers[findSlot(command[1])].LastPrio();
                        int package = couriers[findSlot(command[1])].Dequeue();
                        Console.WriteLine("id: " + Convert.ToString(package) + " prio: " + Convert.ToString(prio));

                        int[] result = new int[2];
                        result[0] = command[1];
                        result[1] = package;

                        results.Add(result);
                    }
                }
                if (command[0] == 4)
                {
                    Console.WriteLine("Move packages from couirer " + command[1] +" to courier " + command[2]);
                    while (!couriers[findSlot(command[1])].Empty)
                    {
                        int prio = couriers[findSlot(command[1])].LastPrio();
                        int package = couriers[findSlot(command[1])].Dequeue();
                        couriers[findSlot(command[2])].Enqueue(package,prio);
                    }
                }
            }

            // print results
            fr.printResults("output.txt", results);

            //Console.ReadKey();
        }