直接看题
一看就很数学
我们不妨来画图
画出几个矩阵,找他们的关系
然后发现
当i==1时,对应的值就是j所对应的值;
当i==n时,所对应的值就是3*n-2-j+1;
当j==1时,所对应的值是4*n-2-i;
当j==n时,对应的值是n+x-1。
然后对于这个很多很多层的矩阵,我们可以对其进行剥层,每剥开一层,n-2,所要求的点相对于新矩阵的行列坐标分别-1,同时值+4*n-4;
这样就是一个递归
Code:
1 #include<bits/stdc++.h> 2 using namespace std; 3 inline int read() 4 { 5 int X=0,w=1; 6 char c=getchar(); 7 while(c<'0'||c>'9') 8 { 9 if (c=='-') 10 { 11 w=-1; 12 } 13 c=getchar(); 14 } 15 while(c>='0'&&c<='9') 16 { 17 X=(X<<3)+(X<<1)+c-'0'; 18 c=getchar(); 19 } 20 return X*w; 21 } 22 inline void out(int n) 23 { 24 if(n<0) 25 { 26 putchar('-'); 27 n=-n; 28 } 29 if(n>=10) 30 { 31 out(n/10); 32 } 33 putchar(n%10+'0'); 34 } 35 inline int jyyakioi(int a,int b,int c) 36 { 37 if(b==1) 38 { 39 return c; 40 } 41 if(c==a) 42 { 43 return b+a-1; 44 } 45 if(b==a) 46 { 47 return 3*(a-1)+1-c+1; 48 } 49 if(c==1) 50 { 51 return 4*(a-1)-(b-2); 52 } 53 return jyyakioi(a-2,b-1,c-1)+4*(a-1); 54 } 55 int main() 56 { 57 int a,b,c; 58 a=read(); 59 b=read(); 60 c=read(); 61 out(jyyakioi(a,b,c)); 62 }
至于jyyakioi,那已经是事实了QwQ