循环赛算法
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<iomanip> 5 using namespace std; 6 int i, j, h, person, n; 7 int a[32 + 1][32 + 1]; 8 9 int main() 10 { 11 cin >> n; 12 person = 1; 13 a[1][1] = 1; 14 h = 1; 15 for(i = 1; i <= n; i++) 16 { 17 person = person * 2; 18 } 19 do 20 { 21 for(i = 1; i <= h; i++) 22 { 23 for(j = 1; j <= h; j++) 24 { 25 a[i][j + h] = a[i][j] + h; 26 a[i + h][j] = a[i][j + h]; 27 a[i + h][j + h] = a[i][j]; 28 } 29 } 30 h *= 2; 31 }while(!(h == person)); 32 33 for(i = 1; i <= h; i++) 34 { 35 for(j = 1; j <= h; j++) 36 { 37 cout << setw(4) << a[i][j]; 38 } 39 cout << endl; 40 } 41 return 0; 42 }