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)); } } }
public TestCase(Car[] cars) { this.cars = cars; }
static Fraction GetOverlappingStartTime(Car car1, Car car2) { return GetTouchingTime(car1, car2, +5); }
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); }
public LaneList(Car[] cars) { lanes = cars.Select(x => x.InitialLane).ToArray(); }
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; }
Fuzzy GetLeaveTime(Car car1, Car car2) { return GetTouchingTime(car1, car2, -5); }
Fuzzy GetEnterTime(Car car1, Car car2) { return GetTouchingTime(car1, car2, +5); }