コード例 #1
0
        static void Main()
        {
            var strs = Console.ReadLine().Split(' ');
            var n    = int.Parse(strs[0]);
            var m    = int.Parse(strs[1]);
            var l    = int.Parse(strs[2]);

            var intervals = new Tuple <int, int> [n];

            for (int i = 0; i < n; ++i)
            {
                strs         = Console.ReadLine().Split(' ');
                intervals[i] = new Tuple <int, int>(
                    int.Parse(strs[0]),
                    int.Parse(strs[1]));
            }
            Array.Sort(intervals);

            var result  = 0;
            var boarded = new OrderedBag <int>();

            foreach (var x in intervals)
            {
                while (boarded.Count > 0)
                {
                    var firstItem = boarded.GetFirst();
                    if (firstItem > x.Item1)
                    {
                        break;
                    }
                    boarded.RemoveFirst();
                    ++result;
                }
                boarded.Add(x.Item2);
                if (boarded.Count > m)
                {
                    boarded.RemoveLast();
                }
            }

            result += boarded.Count;
            Console.WriteLine(result);
        }
コード例 #2
0
ファイル: solution.cs プロジェクト: snetww/judge-solved
        static void Main(string[] args)
        {
            var strs = Console.ReadLine().Split( );
            var n    = int.Parse(strs[0]);
            var m    = int.Parse(strs[1]);
            //var l = int.Parse(strs[2]);

            var tickets = new Tuple <int, int> [n];

            for (int i = 0; i < n; ++i)
            {
                strs       = Console.ReadLine().Split( );
                tickets[i] = new Tuple <int, int>(
                    int.Parse(strs[0]),
                    int.Parse(strs[1]));
            }

            Array.Sort(tickets);

            var selectedTickets = new OrderedBag <int>();
            var result          = n;

            foreach (var ticket in tickets)
            {
                while (selectedTickets.Count > 0 && selectedTickets.GetFirst() <= ticket.Item1)
                {
                    selectedTickets.RemoveFirst();
                }

                selectedTickets.Add(ticket.Item2);
                if (selectedTickets.Count > m)
                {
                    selectedTickets.RemoveLast();
                    --result;
                }
            }

            //result += selectedTickets.Count;
            Console.WriteLine(result);
        }
コード例 #3
0
        public static void Main()
        {
            var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n    = line[0];
            int m    = line[1];

            var orderedBag = new OrderedBag <int>();

            var tickets = new Interval[n];

            for (int i = 0; i < n; i++)
            {
                var passengerInfo = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

                tickets[i] = new Interval(passengerInfo[0], passengerInfo[1]);
            }

            Array.Sort(tickets, (a, b) => a.Start.CompareTo(b.Start));

            var selectedTickets = new OrderedBag <int>();
            int result          = 0;

            foreach (var ticket in tickets)
            {
                while (selectedTickets.Count > 0 && selectedTickets.GetFirst() <= ticket.Start)
                {
                    selectedTickets.RemoveFirst();
                    result++;
                }

                selectedTickets.Add(ticket.End);
                if (selectedTickets.Count > m)
                {
                    selectedTickets.RemoveLast();
                }
            }

            result += selectedTickets.Count;
            Console.WriteLine(result);
        }
コード例 #4
0
        static void Main(string[] args)
        {
            string        input  = Console.ReadLine();
            StringBuilder result = new StringBuilder();

            while (input != "EXIT")
            {
                string[] inputSplit = input.Split();
                string   command    = inputSplit[0];

                if (command == "ADD")
                {
                    short number = short.Parse(inputSplit[1]);

                    if (set2.Count == 0)
                    {
                        set2.Enqueue(number);
                        totalSoFar++;
                        input = Console.ReadLine();
                        continue;
                    }

                    if (number > set2.Peek())
                    {
                        set2.Enqueue(number);
                        totalSoFar++;
                    }
                    else
                    {
                        set1.Add(number);
                        totalSoFar++;
                    }

                    if (set2.Count > set1.Count + 1)
                    {
                        short min = set2.Dequeue();

                        set1.Add(min);
                    }
                    else if (set2.Count < set1.Count)
                    {
                        short max = set1.GetLast();
                        set1.RemoveLast();
                        set2.Enqueue(max);
                    }
                }
                else if (command == "FIND")
                {
                    if (totalSoFar % 2 == 0)
                    {
                        sum  = 0;
                        sum += set1.GetLast() + set2.Peek();
                        sum  = sum / 2;
                        result.AppendLine(sum.ToString());
                    }
                    else if (totalSoFar % 2 == 1)
                    {
                        result.AppendLine(set2.Peek().ToString());
                    }
                }
                input = Console.ReadLine();
            }
            Console.WriteLine(result);
        }
コード例 #5
0
        private void astar(long x, long y)
        {
            double bound = md.n + md.m;
            OrderedBag <KeyValuePair <long, Point> > pq  = new OrderedBag <KeyValuePair <long, Point> >(new cmp());
            OrderedBag <KeyValuePair <long, Point> > pq2 = new OrderedBag <KeyValuePair <long, Point> >(new cmp());

            V2 = new System.Windows.Vector(md.edx - x, md.edy - y);
            V1 = new System.Windows.Vector(1, 0);
            //FastPriorityQueue<node> pq = new FastPriorityQueue<node>(md.n*md.m/10);
            //PriorityQueue pq = new PriorityQueue((IComparer)new cmp());
            pq.Add(new KeyValuePair <long, Point>(G[x, y] + H(new Point((int)x, (int)y)), new Point((int)x, (int)y)));
            //pq.Enqueue(new KeyValuePair<long,Point>(G[x, y] + H(new Point(x, y)), new Point(x, y))));
            G[x, y]   = 1;
            vis[x, y] = true;
            KeyValuePair <long, Point> kvp;

            while (pq.Count != 0)
            {
                if (pq.Count != 0)
                {
                    kvp = pq.RemoveFirst();
                }
                else
                {
                    kvp = pq2.RemoveFirst();
                }
                x = kvp.Value.X;
                y = kvp.Value.Y;
                md.Que.Enqueue(new DrawTask((int)x * md.pW, (int)y * md.pH, md.pW, md.pH, Color.Green));
                Thread.Sleep(md.delay);
                for (long i = 0; i < 4; i++)
                {
                    long g   = x + dir[i, 0];
                    long h   = y + dir[i, 1];
                    long now = kvp.Key;

                    if (g >= 0 && h >= 0 && g < md.n && h < md.m)
                    {
                        if (!vis[g, h] && md.myMaze.maze[g, h] == 0)
                        {
                            G[g, h] = G[x, y] + 1;
                            if (g == md.edx && h == md.edy)
                            {
                                parent[g, h] = new KeyValuePair <long, long>(x, y);
                                md.Que.Enqueue(new DrawTask((int)x * md.pW, (int)y * md.pH, md.pW, md.pH, Color.Green));
                                Thread.Sleep(md.delay);
                                markPath((int)g, (int)h);
                                return;
                            }
                            V1 = new System.Windows.Vector(g - x, h - y);
                            V2 = new System.Windows.Vector(md.edx - x, md.edy - y);
                            long here = G[g, h] + H(new Point((int)g, (int)h));
                            vis[g, h]    = true;
                            parent[g, h] = new KeyValuePair <long, long>(x, y);
                            pq.Add(new KeyValuePair <long, Point>(here, new Point((int)g, (int)h)));
                            if (pq.Count > bound)
                            {
                                pq2.Add(pq.RemoveLast());
                            }
                        }
                    }
                }
            }
        }