Files
python/TangDou/CSP-J/AcWingTraining/T4/459.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

18 lines
478 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
// 推规律,1行j列为j,n行j列为3n-j-1,1行i列为4n-i-2,n行i列为n+i-1。
int dfs(int n, int i, int j) {
if (i == 1) return j;
if (i == n) return 3 * n - j - 1;
if (j == 1) return 4 * n - i - 2;
if (j == n) return n + i - 1;
return dfs(n - 2, i - 1, j - 1) + (n - 1) * 4;
}
int main() {
int n, a, b;
cin >> n >> a >> b;
cout << dfs(n, a, b) << endl;
return 0;
}