AcWing 1219. 移动距离
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF 0x3f3f3f3f
#define endl "\n"
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef long long LL;
const int N = 1e5+3,MOD = 100000007;
int n,m;
int w;
PII get(int t){
int x = t / w,y;
t %= w;//当前行的第几个(无论什么方向)
x -= (t == 0 ? 1 : 0);//具体的第几行
if(x % 2){//从右往左
if(!t) y = 0;
else y = w-(t-1)-1;
}else{//从左往右
if(!t) y = w - 1;
else y = t - 1;
}
return {x,y};
}
void solve(){
while(cin >> w >> m >> n){
PII p1 = get(m),p2 = get(n);
cout << abs(p1.first-p2.first)+abs(p1.second-p2.second) << endl;
}
}
int main(){
#ifdef LOCAL
freopen(".w/ac.in","r",stdin);
freopen(".w/ac.out","w",stdout);
#endif
IOS;
int TT = 1;
// cin >> TT;
while(TT--) solve();
return 0;
}