void PriceOptionsToXML(ref StringBuilder xml, ref PriceOptions opt) { xml.Append(xml_attr("Base_US", opt.BasePrice[0])); xml.Append(xml_attr("Base_EU", opt.BasePrice[1])); xml.Append(xml_attr("Base_RU", opt.BasePrice[2])); xml.Append(xml_attr("Base_SA", opt.BasePrice[3])); xml.Append(xml_attr("PVE", opt.PVE)); xml.Append(xml_attr("PVP", opt.PVP)); xml.Append(xml_attr("Slot1", opt.Slot1)); xml.Append(xml_attr("Slot2", opt.Slot2)); xml.Append(xml_attr("Slot3", opt.Slot3)); xml.Append(xml_attr("Slot4", opt.Slot4)); xml.Append(xml_attr("Slot5", opt.Slot5)); xml.Append(xml_attr("Passworded", opt.Passworded)); xml.Append(xml_attr("MonthX2", opt.MonthX2)); xml.Append(xml_attr("MonthX3", opt.MonthX3)); xml.Append(xml_attr("MonthX6", opt.MonthX6)); xml.Append(xml_attr("WeekX1", opt.WeekX1)); xml.Append(xml_attr("OptNameplates", opt.OptNameplates)); xml.Append(xml_attr("OptCrosshair", opt.OptCrosshair)); xml.Append(xml_attr("OptTracers", opt.OptTracers)); }
void ReadPriceOptions(ref PriceOptions opt) { reader.Read(); opt.BasePrice[0] = getInt("Base_US"); opt.BasePrice[1] = getInt("Base_EU"); opt.BasePrice[2] = getInt("Base_RU"); opt.BasePrice[3] = getInt("Base_SA"); opt.PVE = getInt("PVE"); opt.PVP = getInt("PVP"); opt.Slot1 = getInt("Slot1"); opt.Slot2 = getInt("Slot2"); opt.Slot3 = getInt("Slot3"); opt.Slot4 = getInt("Slot4"); opt.Slot5 = getInt("Slot5"); opt.Passworded = getInt("Passworded"); opt.MonthX2 = getInt("MonthX2"); opt.MonthX3 = getInt("MonthX3"); opt.MonthX6 = getInt("MonthX6"); opt.WeekX1 = getInt("WeekX1"); opt.OptNameplates = getInt("OptNameplates"); opt.OptCrosshair = getInt("OptCrosshair"); opt.OptTracers = getInt("OptTracers"); }
// // WARNING: this code must be in sync with client code // int calcServerRentPrice(ServerRentParams prm) { PriceOptions opt = prm.isGameServer > 0 ? OptGameServer : OptStronghold; // calc base int server_base = 0; switch (prm.regionID) { case 1: server_base = opt.BasePrice[0]; break; case 10: server_base = opt.BasePrice[1]; break; case 20: server_base = opt.BasePrice[2]; break; case 30: server_base = opt.BasePrice[3]; break; default: throw new ApiExitException("bad regionID"); } if (server_base == 0) { return(0); } // calc all other options int price = server_base; //[TH] price is set for slot, not by percents switch (prm.slotID) { case 0: price = opt.Slot1; break; case 1: price = opt.Slot2; break; case 2: price = opt.Slot3; break; case 3: price = opt.Slot4; break; case 4: price = opt.Slot5; break; default: throw new ApiExitException("bad slotID"); } if (prm.password.Length > 0) { price += getServerRentOptionPrice(server_base, opt.Passworded); } if (prm.pveID > 0) { price += getServerRentOptionPrice(server_base, opt.PVE); } else { price += getServerRentOptionPrice(server_base, opt.PVP); } if (prm.nameplates > 0) { price += getServerRentOptionPrice(server_base, opt.OptNameplates); } if (prm.crosshair > 0) { price += getServerRentOptionPrice(server_base, opt.OptCrosshair); } if (prm.tracers > 0) { price += getServerRentOptionPrice(server_base, opt.OptTracers); } // hourly rent, hours is after 100 if (prm.rentID >= HOURLY_RENTID_START) { // 10% add for hourly rent price += price / 10; price = (int)Math.Ceiling((float)price / 24.0f / 31.0f); price = (prm.rentID - HOURLY_RENTID_START) * price; return(price); } // [TH] adjust per day coeff switch (prm.rentID) { case 0: price *= 3; break; case 1: price *= 7; break; case 2: price *= 15; break; case 3: price *= 30; break; case 4: price *= 60; break; default: throw new ApiExitException("bad rentid"); } return(price); }
public static void RunTestcase() { var totalNumberNights = 8; // N var numberOfPrices = 4; // M var numberOfQueries = 1; // Q var priceOptions = new PriceOptions[numberOfPrices]; int[][] values = new int[4][]; values[0] = Array.ConvertAll("100 120 90 110 100 90 130 0".Split(' '), int.Parse); values[1] = Array.ConvertAll("0 0 0 0 0 60 60 0".Split(' '), int.Parse); values[2] = Array.ConvertAll("90 100 80 90 70 80 110 110".Split(' '), int.Parse); values[3] = Array.ConvertAll("88 108 78 98 88 78 118 0".Split(' '), int.Parse); // first M lines for (int i = 0; i < numberOfPrices; i++) { priceOptions[i] = new PriceOptions(); // added after Hackerrank complained runtime error priceOptions[i].SpecialPrices = new List <Price>(); // added after Hackerrank complained runtime error foreach (var item in values[i]) { priceOptions[i].SpecialPrices.Add(new Price(item)); } } int[][] minimumDays = new int[4][]; minimumDays[0] = Array.ConvertAll("0 0 0 0 0 0 0 0".Split(' '), int.Parse); minimumDays[1] = Array.ConvertAll("0 0 0 0 0 0 0 0".Split(' '), int.Parse); minimumDays[2] = Array.ConvertAll("5 5 5 5 5 5 5 5".Split(' '), int.Parse); minimumDays[3] = Array.ConvertAll("0 0 0 0 0 0 0 0".Split(' '), int.Parse); // first M lines for (int i = 0; i < numberOfPrices; i++) { int index = 0; foreach (var item in minimumDays[i]) { priceOptions[i].SpecialPrices[index].MinimumDays = item; index++; } } int[][] maximumDays = new int[4][]; maximumDays[0] = Array.ConvertAll("8 8 8 8 8 8 8 8".Split(' '), int.Parse); maximumDays[1] = Array.ConvertAll("8 8 8 8 8 2 2 8".Split(' '), int.Parse); maximumDays[2] = Array.ConvertAll("8 8 8 8 8 8 8 8".Split(' '), int.Parse); maximumDays[3] = Array.ConvertAll("8 8 8 8 8 8 8 8".Split(' '), int.Parse); // first M lines for (int i = 0; i < numberOfPrices; i++) { int index = 0; foreach (var item in maximumDays[i]) { priceOptions[i].SpecialPrices[index].MaximumDays = item; index++; } } var queries = new Query[numberOfQueries]; // sort priceOptions by priceValue ascending order for (int i = 0; i < numberOfQueries; i++) { queries[i] = new Query(); // added after runtime error var days = new int[] { 1, 7 }; queries[i].CheckinDate = days[0]; queries[i].NumberOfNights = days[1]; var minimumPrices = CalculateMinimumPrices(priceOptions, queries[i]); Console.WriteLine(minimumPrices); } }
public static void ProcessInput() { var numbers = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var totalNumberNights = numbers[0]; // N var numberOfPrices = numbers[1]; // M var numberOfQueries = numbers[2]; // Q var priceOptions = new PriceOptions[numberOfPrices]; // first M lines for (int i = 0; i < numberOfPrices; i++) { priceOptions[i] = new PriceOptions(); // added after Hackerrank complained runtime error priceOptions[i].SpecialPrices = new List <Price>(); // added after Hackerrank complained runtime error var values = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); foreach (var item in values) { priceOptions[i].SpecialPrices.Add(new Price(item)); } } // first M lines for (int i = 0; i < numberOfPrices; i++) { var values = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int index = 0; foreach (var item in values) { priceOptions[i].SpecialPrices[index].MinimumDays = item; index++; } } var maximumDays = new MaximumDays[numberOfPrices]; // first M lines for (int i = 0; i < numberOfPrices; i++) { var values = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int index = 0; foreach (var item in values) { priceOptions[i].SpecialPrices[index].MaximumDays = item; index++; } } var queries = new Query[numberOfQueries]; // number of queries - 1000000 /* * var memo = new Dictionary<int, IList<PriceOptions>>(); * * for(int i = 0; i < totalNumberNights; i++) * { * foreach(var item in priceOptions) * { * var priceOption = item.SpecialPrices[i]; // ? look into later * } * } * */ // too late for the hacking for (int i = 0; i < numberOfQueries; i++) { queries[i] = new Query(); // added after runtime error var values = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); queries[i].CheckinDate = values[0]; queries[i].NumberOfNights = values[1]; // ? /* * var key = values[0] + "," + values[1]; * if(memo.ContainsKey(key)) * { * Console.WriteLine(memo[key]); * return; * } */ var minimumPrices = CalculateMinimumPrices(priceOptions, queries[i]); //memo.Add(key, minimumPrices); Console.WriteLine(minimumPrices); } }