AcWing 1737. 传送
原题链接
简单
作者:
虎头虎脑
,
2022-03-31 22:47:07
,
所有人可见
,
阅读 128
$\color{red}{考虑六种情况就可以了}$
| | 00
00 | |
0 | | 0
| 00 |
| 0 | 0
0 | 0 |
C++ 代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int a, b, x, y;
cin >> a >> b >> x >> y;
if(a > b) swap(a, b);
if(x > y) swap(x, y);
if(x > b || y < a || x < a && y > b) cout << b - a << endl;
else if(x < a && y > a) cout << min(y - a, a - x) + b - y << endl;
else if(x > a && y < b) cout << x - a + b - y << endl;
else cout << min(y - b, b - x) + x - a << endl;
return 0;
}