嗯...
题目链接:https://www.luogu.org/problem/P2239
这道题首先不能暴力建图,没有简单方法,只有进行进行找规律。
AC代码:
1 #include<cstdio> 2 #include<iostream> 3 4 using namespace std; 5 6 inline int work(int n, int x, int y){ 7 if(x == 1) return y; 8 if(y == n) return x + n - 1; 9 if(x == n) return 3 * n - 1 - y; 10 if(y == 1) return 4 * n - 2 - x; 11 return work(n - 2, x - 1, y - 1) + 4 * (n - 1); 12 } 13 14 15 int main(){ 16 int n, x, y; 17 scanf("%d%d%d", &n, &x, &y); 18 printf("%d", work(n, x, y)); 19 return 0; 20 }