7710: USACO 2018 February Contest, Bronze —— Problem 1. Teleportation
[Creator : ]
Description
Farmer John最讨厌的农活是运输牛粪。为了精简这个过程,他制造了一个伟大的发明:便便传送门!与使用拖拉机拖着装满牛粪的大车从一个地点到另一个地点相比,他可以使用便便传送门将牛粪从一个地点瞬间传送到另一个地点。
Farmer John的农场沿着一条长直道路而建,所以他农场上的每个地点都可以简单地用该地点在道路上的位置来表示(相当于数轴上的一个点)。一个传送门可以用两个数 $x$ 和 $y$ 表示,被拖到地点 $x$ 的牛粪可以瞬间传送到地点 $y$,反之亦然。
Farmer John想要将牛粪从地点 $a$ 运输到地点 $b$,他建造了一个可能对这一过程有所帮助的传送门(当然,如果没有帮助,他也可以不用)。请帮助他求出他需要使用拖拉机运输牛粪的总距离的最小值。
One of the farming chores Farmer John dislikes the most is hauling around lots of cow manure. In order to streamline this process, he comes up with a brilliant invention: the manure teleporter! Instead of hauling manure between two points in a cart behind his tractor, he can use the manure teleporter to instantly transport manure from one location to another.
Farmer John's farm is built along a single long straight road, so any location on his farm can be described simply using its position along this road (effectively a point on the number line). A teleporter is described by two numbers $x$ and $y$, where manure brought to location $x$ can be instantly transported to location $y$, or vice versa.
Farmer John wants to transport manure from location aa to location bb, and he has built a teleporter that might be helpful during this process (of course, he doesn't need to use the teleporter if it doesn't help). Please help him determine the minimum amount of total distance he needs to haul the manure using his tractor.
Farmer John想要将牛粪从地点 $a$ 运输到地点 $b$,他建造了一个可能对这一过程有所帮助的传送门(当然,如果没有帮助,他也可以不用)。请帮助他求出他需要使用拖拉机运输牛粪的总距离的最小值。
One of the farming chores Farmer John dislikes the most is hauling around lots of cow manure. In order to streamline this process, he comes up with a brilliant invention: the manure teleporter! Instead of hauling manure between two points in a cart behind his tractor, he can use the manure teleporter to instantly transport manure from one location to another.
Farmer John's farm is built along a single long straight road, so any location on his farm can be described simply using its position along this road (effectively a point on the number line). A teleporter is described by two numbers $x$ and $y$, where manure brought to location $x$ can be instantly transported to location $y$, or vice versa.
Farmer John wants to transport manure from location aa to location bb, and he has built a teleporter that might be helpful during this process (of course, he doesn't need to use the teleporter if it doesn't help). Please help him determine the minimum amount of total distance he needs to haul the manure using his tractor.
Input
输入仅包含一行,为四个用空格分隔的整数:$a$ 和 $b$,表示起始地点和结束地点,后面是 $x$ 和 $y$,表示传送门。所有的位置都是范围为 $0…100$ 的整数,不一定各不相同。
The first and only line of input contains four space-separated integers: $a$ and $b$, describing the start and end locations, followed by $x$ and $y$, describing the teleporter. All positions are integers in the range $0…100$, and they are not necessarily distinct from each-other.
The first and only line of input contains four space-separated integers: $a$ and $b$, describing the start and end locations, followed by $x$ and $y$, describing the teleporter. All positions are integers in the range $0…100$, and they are not necessarily distinct from each-other.
Output
输出一个整数,为 Farmer John 需要用拖拉机运输牛粪的最小距离。
Print a single integer giving the minimum distance Farmer John needs to haul manure in his tractor.
Print a single integer giving the minimum distance Farmer John needs to haul manure in his tractor.
Sample 1 Input
3 10 8 2
Sample 1 Output
3
在这个样例中,最佳策略是将牛粪从位置 3 运到位置 2,传送到位置 8,再运到位置 10。 所以需要用拖拉机的总距离为 1 + 2 = 3。