#include #include // ceil関数を使うため using namespace std; int min_commands(int X, int Y, int L) { int commands = 0; // Y方向 (北または南) に移動 if (Y > 0) { // 北に進む commands += (Y + L - 1) / L; // 必要な前進命令の回数を計算 } else if (Y < 0) { // 南に進む commands += 1; // 南に向きを変える命令 commands += (-Y + L - 1) / L; // 必要な前進命令の回数を計算 } // X方向 (東または西) に移動 if (X > 0) { // 東に進む commands += 1; // 東に向きを変える命令 commands += (X + L - 1) / L; // 必要な前進命令の回数を計算 } else if (X < 0) { // 西に進む commands += 1; // 西に向きを変える命令 commands += (-X + L - 1) / L; // 必要な前進命令の回数を計算 } return commands; } int main() { int X, Y, L; // 標準入力 cin >> X >> Y >> L; // 必要な最小の命令回数を出力 cout << min_commands(X, Y, L) << endl; return 0; }