'commit'
This commit is contained in:
18
TangDou/CSP-J/AcWingTraining/T4/459.cpp
Normal file
18
TangDou/CSP-J/AcWingTraining/T4/459.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user