1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| #include <iostream> #include <cstring> #include <algorithm> using namespace std; int n,m,w; int main() {cin>>w>>m>>n; m--; n--; int x1=m/w,x2=n/w; int y1=m%w,y2=n%w; if(x1%2)y1=w-1-y1; if(x2%2)y2=w-1-y2;
int res=abs(x1-x2)+abs(y1-y2); cout<<res; return 0; }
|