We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Data Structures
- Queues
- Truck Tour
- Discussions
Truck Tour
Truck Tour
Sort by
recency
|
368 Discussions
|
Please Login in order to post a comment
This problem really reminds me of planning real-world routes — kind of like how logistics or travel planning works. It’s similar to when you’re exploring Top Attractions in Abu Dhabi, figuring out the most efficient way to visit all the must-see spots without wasting time or energy. Just like the truck finding the best starting point, it’s all about smart planning and balance. Really interesting discussion!
I recently came across a similar problem where I had to figure out the best starting point for a petrol pump tour on a circle. After some thinking, I realized that it's like solving a puzzle, much like in games. It reminded me of TruckersofEuropeAPK, a modified version of Truckers of Europe 3, where you're tasked with transporting cargo across European cities, just like the truck in this problem. In TruckersofEuropeAPK, all the premium features are unlocked, and it’s as if you’re calculating the best route in real life. Definitely a cool experience if you're into driving simulation games!
Save the previous circle you already calculated, in a way you can speed it up via memoization. After each pump you can add that pump's total cost to the cost of the pumps before it. Using this strategy you will never have to recalclate the beginning of the loop.
There's probably other ways to optimize it, but I got lazy after memoizing the beginning part of the loop. This way you never have to worry about trying to loop back your array around.
Im getting an error with this:
int fuel = 0; int miles = 0; int index = 0; for (int i = 0; i < petrolpumps.size(); i++) { fuel += petrolpumps.get(i).get(0); miles += petrolpumps.get(i).get(1); if (fuel < miles) { fuel = 0; miles = 0; index = i + 1; } } return index;However if I change the inequality to this "if (fuel - miles < 0)" ,it is passing all the test cases. They are both supposed to be the same according to linear inequalities. This is math defying. Please help.