传送门
题目大意:
农夫要把牛粪从a运到b,但是呢他不想走这么长的路,于是他造了个传送门(Excuse me?有钱真好),传送门可以从x传送到y,问农夫最少要走多远?
题目分析:
水到不能再水的题,可是居然还wa了一发(哭),一开始惯性思维以为 a<b 所以错了(泪)。
这里分两种情况就好了:
传送:路程S=abs(a-x/y)+abs(b-y/x)
不传送:S=abs(a-b)
代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main(){
int a,b,x,y;
cin>>a>>b>>x>>y;
int tmp=abs(b-a);
int ano=0;
if(abs(a-x)<abs(a-y)){
ano+=abs(a-x);
ano+=abs(b-y);
}
else{
ano+=abs(a-y);
ano+=abs(b-x);
}
int ans=min(ano,tmp);
cout<<ans<<endl;
return 0;
}