题目描述 :http://codeforces.com/problemset/problem/1020/A
c++代码:
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n,h,a,b,k;
cin >> n >> h >> a >> b>> k;
while(k--) {
int ta,fa,tb,fb;
cin >> ta >> fa >> tb >> fb;
long long ans=0;
if(ta!=tb) {
if(fa>b) {
ans+=fa-b;
ans+=abs(ta-tb);
ans+=abs(b-fb);
}
else if(fa<=b&&fa>=a) {
ans+=abs(ta-tb);
ans+=abs(fa-fb);
}
else {
ans+=a-fa;
ans+=abs(ta-tb);
ans+=abs(a-fb);
}
cout << ans <<endl;
}
else cout << abs(fa-fb) <<endl;
}
return 0;
}