1 #include<iostream>
2 #include<iomanip>
3 using namespace std;
4 #define max(a,b) ((a)>(b) ? (a) : (b))
5 #define abs(a) ((a)>0 ? (a) : (-a))
6 int foo(int x, int y)
7 {
8 int t = max(abs(x),abs(y));
9 int v;
10 int u = 2 * t -1;
11 u = u * u;
12 if(t == -x)
13 v = u + 5 * t -y;
14 else if(t == -y)
15 v = u + 7 * t +x;
16 else if(t == y)
17 v = u + 3 * t -x;
18 else
19 v = u + t + y;
20 return v;
21 }
22
23 int main()
24 {
25 int i,j;
26 for(i=-4; i <= 4; i++){
27 for(j=-4; j <= 4; j++)
28 cout<<" "<< setw(5)<<foo(j,i)<<" ";
29 cout << endl;
30 }
31 }
![](//images0.cnblogs.com/i/502473/201407/281604539932355.png)