P8623 [蓝桥杯 2015 省 B] 移动距离
- 题目
- 解析
- 代码
题目
解析
完了完了T.T,这个题我做了20分钟
解题思路就是分组,但是编写的时候最好把边界值过一遍【题目提供的测试数据肯定是最好通过的数据,需要你自己过一遍特殊数据,然后再测试自己的代码】我就是这样被卡20minsQAQ
代码
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>#include <cctype>
using namespace std;
int w, m, n;
int h1, l1, h2, l2;
int main() {cin >> w >> m >> n;h1 = (m - 1) / w;if (h1 % 2 == 0)l1 = m % w;elsel1 = w - (m % w) + 1;h2 = (n - 1) / w;if (h2 % 2 == 0)l2 = n % w;elsel2 = w - n % w + 1;cout << abs(h2 - h1 ) + abs(l2 - l1);return 0;
}