static void Main(string[] args) { int numberOfPumps = int.Parse(Console.ReadLine()); Queue <PetrolPump> circle = new Queue <PetrolPump>(); for (int i = 0; i < numberOfPumps; i++) { var input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(); var currentPump = new PetrolPump(input[0], input[1], i); circle.Enqueue(currentPump); } var count = 0; while (count <= circle.Count) { var moves = 0; var fuel = 0; while (true) { var quantity = circle.Peek().Quantity; var disctance = circle.Peek().DistanceToTheNext; fuel = fuel + quantity - disctance; if (fuel >= 0) { circle.Enqueue(circle.Dequeue()); moves += 1; } else { circle.Enqueue(circle.Dequeue()); break; } if (moves == circle.Count) { goto next; } } count++; } next: Console.WriteLine(circle.Peek().Index);; }
public PetrolPump_ViewModel(MainWindow_ViewModel newMainViewModel, PetrolPump petrolPump) { MainWindowViewModel = newMainViewModel; PetrolPumpModel = petrolPump; Taps = petrolPump.Taps; PetrolPumpTankCommand = new TankCommand(newMainViewModel, this); FinishedPumping = new FinishedCommand(this); LiterGetankt = 0; IsPumping = false; allPumpVMs.Add(this); }
static void Main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */ int n = int.Parse(Console.ReadLine()); PetrolPump[] q = new PetrolPump[n]; for (int i = 0; i < n; i++) { int[] info = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); q[i] = new PetrolPump(info[0], info[1]); } TruckTour(q, n); }
static void Main(string[] args) { int petrolPumpsCount = int.Parse(Console.ReadLine()); Queue <PetrolPump> petrolPumps = new Queue <PetrolPump>(); for (int i = 0; i < petrolPumpsCount; i++) { int[] nums = Console.ReadLine() .Split(' ') .Select(int.Parse) .ToArray(); int amountOfPetrol = nums[0], distanceToNextPump = nums[1]; petrolPumps.Enqueue(new PetrolPump(amountOfPetrol, distanceToNextPump)); } for (int i = 0; i < petrolPumpsCount; i++) { long tankFuel = 0; bool hasFuel = true; for (int j = 0; j < petrolPumpsCount; j++) { if (hasFuel) { PetrolPump currentPump = petrolPumps.Peek(); tankFuel += currentPump.AmountOfPetrol - currentPump.DistanceToNextPump; if (tankFuel < 0) { hasFuel = false; } } petrolPumps.Enqueue(petrolPumps.Dequeue()); } if (hasFuel) { Console.WriteLine(i); break; } petrolPumps.Enqueue(petrolPumps.Dequeue()); } }
/// <summary> /// Nachdem der offene Betrag für die Pumpe beglichen wurde, wird diese wieder reseted und freigegeben /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static void PumpIsPayedVM(object sender, EventArgs e) { foreach (PetrolPump_ViewModel pumpVM in allPumpVMs) { PetrolPump pumpModel = pumpVM.PetrolPumpModel = pumpVM.MainWindowViewModel.PetrolPumps .FirstOrDefault(x => x.Number == pumpVM.PetrolPumpModel.Number); if (pumpModel.WasUsed == false) { pumpVM.Cost = 0; pumpVM.LiterGetankt = 0; pumpVM.IsPumping = false; } } }
public static void Main1() { PetrolPump[] arr = new PetrolPump[] { new PetrolPump(2, 5), //-3 new PetrolPump(7, 5), //2 new PetrolPump(9, 4), //5 new PetrolPump(8, 11), //-3 new PetrolPump(4, 9), //-5 new PetrolPump(7, 4), new PetrolPump(6, 6) }; var index = PrintTour(arr); Console.WriteLine(index); }
public void FinishedBuying(PetrolPump usedPump) { usedPump.WasUsed = false; usedPump.AmountOwned = 0; }