AcWing 1737. 传送
原题链接
简单
作者:
Hangya
,
2022-03-31 21:44:27
,
所有人可见
,
阅读 150
算法1
(暴力判断) $O(1)$
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int N=2010;
#define INF 0x3f3f3f3f
#define x first
#define y second
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
typedef long long ll;
int x,y,st,ed;
int main()
{
cin>>st>>ed>>x>>y;
if(x>y) swap(x,y);
if(st>ed) swap(st,ed);
if(st==ed)
{
cout<<0<<endl;
return 0;
}
if(x==y)
{
cout<<ed-st<<endl;
return 0;
}
if(y<=st||x>=ed) cout<<ed-st<<endl;
else if(st>=x&&st<=y&&ed>=y)
cout<<min(st-x+ed-y,ed-st)<<endl;
else if(ed>=x&&ed<=y&&st<=x)
cout<<min(ed-st,x-st+y-ed)<<endl;
else if(st<=x&&ed>=y) cout<<x-st+ed-y<<endl;
else if(st>=x&&ed<=y)
cout<<min(ed-st,st-x+y-ed)<<endl;
return 0;
}