USACO 2018 February Contest Bronze Division - Teleportation
Problem link: here
Solution Author: Stefan Dascalescu
Problem Solution
All we need to do is casework based on where the teleporters are.
Source codes
The source codes in C++ and Python can be seen below.
#include <bits/stdc++.h>
using namespace std;
int main()
{
ifstream cin("teleport.in");
ofstream cout("teleport.out");
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << min(abs(b-a), min(abs(a-c) + abs(d-b), abs(a-d) + abs(c-b)));
return 0;
}
with open("teleport.in", "r") as f:
a, b, c, d = map(int, f.readline().split())
result = min(abs(b - a), min(abs(a - c) + abs(d - b), abs(a - d) + abs(c - b)))
with open("teleport.out", "w") as f:
f.write(str(result))