-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path94_C.cpp
55 lines (51 loc) · 1.02 KB
/
94_C.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
44
45
46
47
48
49
50
51
52
53
54
55
#include<iostream>
using namespace std;
int main()
{
int n,m,a,b;
cin>>n>>m>>a>>b;
bool aStart = ( a - 1 ) % m == 0 ? true : false;
bool bEnd = ( b - m ) % m ==0 || b == n ? true : false;
bool aEnd = ( a - m) % m == 0 && a-m >=1 ? true : false;
int bStart = ( b - 1 )% m == 0 ? true : false;
int aRow = 0, bRow = 0;
aRow = a%m == 0 ? a/m : a/m+1;
bRow = b%m == 0 ? b/m : b/m+1;
bool checkB = ( b - m ) % m ==0;
if(aStart && bEnd)
{
cout<<"1"<<endl;
}
else if(!aStart && bEnd)
{
//check for same row
if(aRow == bRow)
cout<<"1"<<endl;
else
cout<<"2"<<endl;
}
else if(aStart && !bEnd)
{
if(aRow == bRow)
cout<<"1"<<endl;
else
cout<<"2"<<endl;
}
else
{
int bTrail = b - 1 - (bRow-1)*m;
int aTrail = a - 1 - (aRow-1)*m;
if(!bStart)
bTrail++;
aTrail++;
if(aRow == bRow)
cout<<"1"<<endl;
else if((bRow == aRow + 1) || (aTrail + bTrail == m && bTrail<aTrail && !aEnd))
cout<<"2"<<endl;
else if(aEnd && bTrail == m-1)
cout<<"2"<<endl;
else
cout<<"3"<<endl;
}
return 0;
}