示例#1
0
 public bool IsSameAs(Location otherLocation)
 {
     return this.X == otherLocation.X && this.Y == otherLocation.Y;
 }
示例#2
0
 public double DistanceTo(Location otherLocation)
 {
     return Math.Sqrt((this.X - otherLocation.X).Pow2() + (this.Y - otherLocation.Y).Pow2());
 }
示例#3
0
 public double DistanceToVia(Location otherLocation, Location via)
 {
     return this.DistanceTo(via) + via.DistanceTo(otherLocation);
 }
示例#4
0
        static void Main(string[] args)
        {
            string _inputFile = args[0];
            string _outputFile = Path.ChangeExtension(_inputFile, "out");
            var _start = DateTime.Now;

            using (var _input = new StreamReader(_inputFile))
            {
                using (var _output = new StreamWriter(_outputFile))
                {
                    var _testCases = _input.ReadLine();
                    string _line;
                    int _case = 0;

                    while((_line = _input.ReadLine()) != null)
                    {
                        ++_case;

                        var _parts = _line.Split(' ');
                        var _numOfProducts = int.Parse(_parts[0]);
                        var _numOfShops = int.Parse(_parts[1]);
                        var _gasPrice = double.Parse(_parts[2]);

                        IEnumerable<Product> _products = _input.ReadLine().Split(' ').Select(s => new Product(s));

                        var _locations = new List<Location>();
                        var _home = new Location("home", 0, 0);
                        _locations.Add(_home);

                        Enumerable.Range(1, _numOfShops).ToList().ForEach(x => {
                            _parts = _input.ReadLine().Split(' ');
                            var _loc = new Location(string.Format("{0}.{1}", _case, x.ToString()), int.Parse(_parts[0]), int.Parse(_parts[1]));
                            _loc.Products = _parts.Skip(2).Select(s => {
                                var _a = s.Split(':');
                                return _products.GetByName(_a[0]).Clone(double.Parse(_a[1]));
                            });
                            _locations.Add(_loc);
                        });

                        var _firstOne = new Purchase() { Location = _locations.GetHome(), Cost=0.0, IsPerishable=false, Product=null};
                        var _memoizer = new Dictionary<string, double>();
                        Console.WriteLine(string.Format("Calculating Case # {0}...", _case));
                        var _minAmount = MinCostForAcquiring(_products, _firstOne, _locations, _gasPrice, _memoizer);
                        Console.WriteLine(string.Format("Done...result={0}", _minAmount));
                        Console.WriteLine();
                        _output.WriteLine(string.Format("Case #{0}: {1}", _case, Math.Round(_minAmount, 7).ToString("F7", new CultureInfo("en-US"))));
                    }
                }
            }
            Console.WriteLine(string.Format("Duration: {0}", DateTime.Now.Subtract(_start).ToString()));
            Console.ReadLine();
        }