Esempio n. 1
0
 public static int CompareBelts(Belt b1, Belt b2)
 {
     if (b1.speed > b2.speed)
     {
         return(1);
     }
     else if (b1.speed == b2.speed)
     {
         return(0);
     }
     else
     {
         return(-1);
     }
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            TextReader tr = new StreamReader("A-large-0.in");
            TextWriter tw = new StreamWriter("A-large-0.out");

            string line    = tr.ReadLine();
            long   numTest = long.Parse(line);

            for (long testi = 0; testi < numTest; testi++)
            {
                string[] elements = tr.ReadLine().Split(' ');
                int      X        = int.Parse(elements[0]);
                int      S        = int.Parse(elements[1]);
                int      R        = int.Parse(elements[2]);
                int      t        = int.Parse(elements[3]);
                int      N        = int.Parse(elements[4]);

                Belt[] belts = new Belt[N + 1];

                int allLength = 0;

                for (int i = 0; i < N; i++)
                {
                    elements        = tr.ReadLine().Split(' ');
                    belts[i].length = int.Parse(elements[1]) - int.Parse(elements[0]);
                    belts[i].speed  = int.Parse(elements[2]);

                    allLength += belts[i].length;
                }

                belts[N].length = X - allLength;
                belts[N].speed  = 0;

                Array.Sort(belts, CompareBelts);

                double runLeft   = t;
                double totalTime = 0;

                for (int i = 0; i < N + 1; i++)
                {
                    if (runLeft >= (double)belts[i].length / (double)(belts[i].speed + R))
                    {
                        double currTime = (double)belts[i].length / (double)(belts[i].speed + R);
                        totalTime += currTime;
                        runLeft   -= currTime;
                    }
                    else if (runLeft > 0)
                    {
                        double runLength = (belts[i].speed + R) * runLeft;

                        double leftLength = belts[i].length - runLength;

                        double leftTime = (double)leftLength / (double)(belts[i].speed + S);

                        totalTime += (runLeft + leftTime);
                        runLeft    = 0;
                    }
                    else
                    {
                        double currTime = (double)belts[i].length / (double)(belts[i].speed + S);
                        totalTime += currTime;
                    }
                }


                CultureInfo cult = new CultureInfo("en-US");


                tw.WriteLine("Case #{0}: {1}", testi + 1, totalTime.ToString(cult));
                Console.WriteLine("Case #{0}: {1}", testi + 1, totalTime.ToString(cult));
            }

            tr.Close();
            tw.Close();
            Console.ReadKey();
        }