Ejemplo n.º 1
0
        public InputFile(string filePath)
        {
            using (var file = File.OpenText(filePath))
            {
                var testCaseCount = int.Parse(file.ReadLine());

                testCases = new List<TestCase>(testCaseCount);

                for (var i = 0; i < testCaseCount; i++)
                {
                    var N = ReadInts(file)[0];
                    var cars = new Car[N];

                    for (var j = 0; j < N; j++)
                    {
                        var tokens = ReadStrings(file);
                        cars[j] = new Car(
                            tokens[0] == "L" ? Lane.Left : Lane.Right,
                            int.Parse(tokens[1]),
                            int.Parse(tokens[2]));
                    }

                    testCases.Add(new TestCase(cars));
                }
            }
        }
Ejemplo n.º 2
0
 public TestCase(Car[] cars)
 {
     this.cars = cars;
 }
Ejemplo n.º 3
0
 static Fraction GetOverlappingStartTime(Car car1, Car car2)
 {
     return GetTouchingTime(car1, car2, +5);
 }
Ejemplo n.º 4
0
        static Fraction GetTouchingTime(Car car1, Car car2, int offset)
        {
            if (car1.Speed < car2.Speed)
                ToolBox.Swap(ref car1, ref car2);

            return new Fraction(car1.InitialPosition - car2.InitialPosition + offset, car2.Speed - car1.Speed);
        }
Ejemplo n.º 5
0
 public LaneList(Car[] cars)
 {
     lanes = cars.Select(x => x.InitialLane).ToArray();
 }
Ejemplo n.º 6
0
        Fuzzy GetTouchingTime(Car car1, Car car2, double offset)
        {
            if (car1.Speed < car2.Speed)
                ToolBox.Swap(ref car1, ref car2);

            var time = (car1.InitialPosition - car2.InitialPosition + offset) / (car2.Speed - car1.Speed);

            if (time == 0) return Fuzzy.Epsilon;

            return time;
        }
Ejemplo n.º 7
0
 Fuzzy GetLeaveTime(Car car1, Car car2)
 {
     return GetTouchingTime(car1, car2, -5);
 }
Ejemplo n.º 8
0
 Fuzzy GetEnterTime(Car car1, Car car2)
 {
     return GetTouchingTime(car1, car2, +5);
 }