You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
478 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
// 推规律1行j列为jn行j列为3n-j-11行i列为4n-i-2n行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;
}