You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
# define N 8 //运行结果正确, 但是N不能太大, 不然一个屏幕占不下
//开一个二维数组
int a [ 101 ] [ 101 ] = { 0 } ;
void table ( ) {
int i , j , t , n = 2 , temp ;
//因为前4个格子已经填好, 所以不必循环到t==2。迭代处理, 依次处理2^2, …, 2^k个选手比赛日程
for ( t = 4 ; t < = N ; t * = 2 ) {
temp = n ;
n * = 2 ; //第一次进来时, n=2, 每执行一次循环n增大一倍
//填左下角元素(构建变量的增量值, 然后增加n后复制到左下角)
for ( i = temp + 1 ; i < = n ; i + + ) {
for ( j = 1 ; j < = temp ; j + + ) {
a [ i ] [ j ] = a [ i - temp ] [ j ] + temp ;
}
}
//填右上角元素(右上角是从左下角拷贝过来的)
for ( i = 1 ; i < = temp ; i + + ) {
for ( j = temp + 1 ; j < = n ; j + + ) {
a [ i ] [ j ] = a [ i + temp ] [ j - temp ] ;
}
}
//填右下角元素(直接从左上角复制过来)
for ( i = temp + 1 ; i < = n ; i + + ) {
for ( j = temp + 1 ; j < = n ; j + + ) {
a [ i ] [ j ] = a [ i - temp ] [ j - temp ] ;
}
}
}
}
int main ( ) {
int i , j ;
a [ 1 ] [ 1 ] = 1 ;
a [ 1 ] [ 2 ] = 2 ;
a [ 2 ] [ 1 ] = 2 ;
a [ 2 ] [ 2 ] = 1 ;
//主函数
table ( ) ;
//输出
for ( i = 1 ; i < = N ; i + + ) {
for ( j = 1 ; j < = N ; j + + )
cout < < a [ i ] [ j ] < < " \t " ;
cout < < endl ;
}
return 0 ;
}