-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path1020A. New Building for SIS.cpp
43 lines (36 loc) · 1.1 KB
/
1020A. New Building for SIS.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
Idea:
- If the towers are the same then the answer is the absolute
difference between the floors.
- If the towers are not the same then try to move from the
first tower to the second using the minimum number of steps.
- The minimum number of steps is to move first from the
current floor to points `a` or `b` (if the current floor
is not inside them), then move to the second tower and move
from the current floor to the target one.
*/
#include <bits/stdc++.h>
using namespace std;
int n, h, a, b, k;
int main() {
scanf("%d %d %d %d %d", &n, &h, &a, &b, &k);
for(int i = 0, fa, ta, fb, tb; i < k; ++i) {
scanf("%d %d %d %d", &ta, &fa, &tb, &fb);
if(ta == tb)
printf("%d\n", abs(fa - fb));
else {
int res = 0;
if(fa >= a && fa <= b) {
res += abs(ta - tb);
res += abs(fa - fb);
} else {
if(abs(fa - a) < abs(fa - b))
res += abs(fa - a) + abs(ta - tb) + abs(fb - a);
else
res += abs(fa - b) + abs(ta - tb) + abs(fb - b);
}
printf("%d\n", res);
}
}
return 0;
}