返回题解分享
讨论 / 题解分享/ 帖子详情

移动距离(编程题) - 题解

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

int w, n, m;

int main()
{
    cin >> w >> m >> n;
    m--, n--;
    int x1, y1, x2, y2;
    x1 = m/w, x2 = n/w;
    if((m/w)%2!=0)
        y1 = w - 1 - m%w;
    else
        y1 = m%w;
    if((n/w)%2!=0)
        y2 = w - 1 - n%w;
    else
        y2 = n%w;
    cout << abs(x1 - x2) + abs(y1 - y2);
    return 0;
}
0 回复 0 转发 0 喜欢 1 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!