Ejemplo n.º 1
0
 public void AddParkingSpace(ParkingSpace parkingSpace)
 {
     if (this.BestParkingSpace == null ||
         parkingSpace.DistanceFromTarget < this.BestParkingSpace.DistanceFromTarget)
     {
         this.BestParkingSpace = parkingSpace;
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var zones             = new List <ParkingZone>();
            var freeParkingSpaces = new List <ZonedParkingSpace>();

            var zonesToReceive = int.Parse(Console.ReadLine());

            for (var i = 0; i < zonesToReceive; i++)
            {
                var split  = Console.ReadLine().Split(": ,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                var color  = split[0];
                var x      = int.Parse(split[1]);
                var y      = int.Parse(split[2]);
                var width  = int.Parse(split[3]);
                var height = int.Parse(split[4]);
                var price  = double.Parse(split[5]);
                var zone   = new ParkingZone(color, x, y, width, height, price);

                zones.Add(zone);
            }

            var splitSpaces = Console.ReadLine().Split(", ;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            for (var i = 0; i < splitSpaces.Length; i += 2)
            {
                var x            = int.Parse(splitSpaces[i]);
                var y            = int.Parse(splitSpaces[i + 1]);
                var unzonedSpace = new ParkingSpace(x, y);
                foreach (var zone in zones)
                {
                    if (zone.IsInside(unzonedSpace))
                    {
//                        Console.WriteLine($"{unzonedSpace.X} {unzonedSpace.Y} is inside {zone.Color}");
                        freeParkingSpaces.Add(zone.GetParkingSpace(unzonedSpace));
                    }
                }
            }

            var pointSplit = Console.ReadLine().Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            var store = new TargetPoint(int.Parse(pointSplit[0]), int.Parse(pointSplit[1]));


            var k = int.Parse(Console.ReadLine());

            var lowestPrice = double.MaxValue;
            ZonedParkingSpace lowestPriceSpace = null;

            foreach (var space in freeParkingSpaces)
            {
                var priceToStore = space.GetPriceToPointAndBack(store, k);
//                Console.WriteLine($"{space.X} {space.Y} zone: {space.Zone.Color} dist: {store.GetDistance(space)} price: {priceToStore}");
                if (priceToStore < lowestPrice)
                {
                    lowestPrice      = priceToStore;
                    lowestPriceSpace = space;
                }
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                else if (lowestPrice == priceToStore && space.GetTimeInSeconds(store, k) <
                         lowestPriceSpace.GetTimeInSeconds(store, k))
                {
                    lowestPrice      = priceToStore;
                    lowestPriceSpace = space;
                }
            }


            Console.WriteLine("Zone Type: {0}; X: {1}; Y: {2}; Price: {3:f2}", lowestPriceSpace.Zone.Color, lowestPriceSpace.X, lowestPriceSpace.Y, lowestPrice);
//            Main(args);
        }
Ejemplo n.º 3
0
 public int GetDistance(ParkingSpace space)
 {
     return(Math.Abs(X - space.X) + Math.Abs(Y - space.Y) - 1);
 }
Ejemplo n.º 4
0
 public ZonedParkingSpace GetParkingSpace(ParkingSpace space)
 {
     return(new ZonedParkingSpace(space.X, space.Y, this));
 }
Ejemplo n.º 5
0
 public bool IsInside(ParkingSpace space)
 {
     return(space.X >= X && space.X < EndX && space.Y >= Y && space.Y < EndY);
 }
Ejemplo n.º 6
0
            public static void Main()
            {
                int         zonesCount = int.Parse(Console.ReadLine());
                List <Zone> zones      = new List <Zone>();

                for (int i = 0; i < zonesCount; i++)
                {
                    string[] tokens     = Console.ReadLine().Split(':');
                    string   name       = tokens[0];
                    string[] parameters = tokens[1].Split(',');
                    uint     x          = uint.Parse(parameters[0]);
                    uint     y          = uint.Parse(parameters[1]);
                    uint     width      = uint.Parse(parameters[2]);
                    uint     height     = uint.Parse(parameters[3]);
                    double   price      = double.Parse(parameters[4]);
                    zones.Add(new Zone(name, x, y, width, height, price));
                }

                string[] parkSpaces = Console.ReadLine().Split(';');

                string[] targetTokens = Console.ReadLine().Split(',');
                uint     targetX      = uint.Parse(targetTokens[0]);
                uint     targetY      = uint.Parse(targetTokens[1]);

                uint timeConstant = uint.Parse(Console.ReadLine());

                for (int i = 0; i < parkSpaces.Length; i++)
                {
                    string[]     tokens = parkSpaces[i].Split(',');
                    uint         x      = uint.Parse(tokens[0]);
                    uint         y      = uint.Parse(tokens[1]);
                    ParkingSpace space  = new ParkingSpace(x, y, targetX, targetY);
                    for (int j = 0; j < zones.Count; j++)
                    {
                        if (x >= zones[j].MinX && x < zones[j].MaxX && y >= zones[j].MinY && y < zones[j].MaxY)
                        {
                            zones[j].AddParkingSpace(space);
                            break;
                        }
                    }
                }

                ParkingSpace bestParkingSpace = null;
                decimal      totalPrice       = Decimal.MaxValue;
                uint         totalTime        = int.MaxValue;
                string       zoneName         = string.Empty;

                for (int i = 0; i < zones.Count; i++)
                {
                    ParkingSpace currentBest = zones[i].BestParkingSpace;
                    if (currentBest != null)
                    {
                        uint    currentTime  = currentBest.DistanceFromTarget * 2 * timeConstant;
                        uint    timeInMins   = currentTime % 60 == 0 ? currentTime / 60 : currentTime / 60 + 1;
                        decimal currentPrice = timeInMins * (decimal)zones[i].PricePerMin;
                        if (currentPrice < totalPrice || (currentPrice == totalPrice && currentTime < totalTime))
                        {
                            totalTime        = currentTime;
                            totalPrice       = currentPrice;
                            bestParkingSpace = currentBest;
                            zoneName         = zones[i].Name;
                        }
                    }
                }

                Console.WriteLine("Zone Type: {0}; X: {1}; Y: {2}; Price: {3:F2}", zoneName, bestParkingSpace.X, bestParkingSpace.Y, totalPrice);
            }