Пример #1
0
        public override long Calculate(ProblemInput input, ProblemOutput output)
        {
            long result = 0;

            foreach (var car in output.Cars)
            {
                Coordinate location = new Coordinate();
                long       time     = 0;
                foreach (var ride in car.RidesTaken)
                {
                    int  distance     = location.CalcGridDistance(ride.Start);
                    long minStartTurn = Math.Max(time + distance, ride.StartTime);
                    if (ride.StartTime >= minStartTurn)
                    {
                        result += input.Bonus;
                    }

                    time     = minStartTurn + ride.Distance;
                    location = ride.End;
                    result  += ride.Distance;
                }
            }

            return(result);
        }
Пример #2
0
        private static bool Apply(ProblemInput input, bool assignedRide, IEnumerable <Car> cars)
        {
            foreach (var car in cars)
            // foreach (var car in input.Cars)
            {
                double     minScore = double.MaxValue;
                Ride       maxRide  = null;
                Coordinate currLoc  = car.CurrentTime > 0 ? car.RidesTaken.Last().End : new Coordinate(0, 0);
                foreach (var ride in input.Rides)
                {
                    // TODO: break cond
                    var score = ScoreCalc.GetScore(ride, currLoc, car.CurrentTime, input);
                    if (score < minScore)
                    {
                        minScore     = score;
                        maxRide      = ride;
                        assignedRide = true;
                    }
                }

                if (maxRide != null)
                {
                    input.Rides.Remove(maxRide);
                    car.RidesTaken.Add(maxRide);
                    long minStartTurn = Math.Max(car.CurrentTime + currLoc.CalcGridDistance(maxRide.Start),
                                                 maxRide.StartTime);

                    car.CurrentTime = minStartTurn + maxRide.Distance;
                }
            }

            return(assignedRide);
        }
Пример #3
0
        //public static double GetScoreBonus(Ride ride, Coordinate location, long currTime, ProblemInput input)
        //{
        //    long distance = GetDistance(ride.Start, location);
        //    long minStartTurn = Math.Max(currTime + distance, ride.StartTime);
        //    long timeToStart = minStartTurn - currTime;
        //    timeToStart = timeToStart < 0 ? 0 : timeToStart;

        //    if (IsNotValid(ride, input, minStartTurn, timeToStart))
        //        return -1;

        //    return 1.0 / timeToStart;

        //    double scoreWithBonus = timeToStart * 2 / Math.Sqrt(ride.Distance);

        //    return scoreWithBonus / Math.Sqrt(input.Bonus);
        //}

        public static long GetDistance(Coordinate x, Coordinate y)
        {
            return(x.CalcGridDistance(y));
        }