Explanation
We can consider three possibilities:
- Farmer John did not use any teleporter to transport the manure, so he travels a distance of .
- Farmer John travels to point from , teleports the manure to , then travels to , for a distance of .
- Farmer John travels to point from , teleports the manure to , then travels to , for a distance of .
We can calculate the minimum distance he needs to haul the manure using his tractor among the above possibilities.
Implementation
Time Complexity:
#include <bits/stdc++.h>using namespace std;int main() {freopen("teleport.in", "r", stdin);freopen("teleport.out", "w", stdout);int a, b, c, d;cin >> a >> b >> c >> d;/*
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!