|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这个代码在n<=2时还正常,n>=3就无法显示。。。
- #include <stdio.h>
- #include <math.h>
- int a[129][129]={0};
- /*
- void Do(int maxs)
- {
- int i,j,t,currs,pres;
- currs=2;
- a[1][1]=1;
- a[1][2]=2;
- a[2][1]=2;
- a[2][2]=1;
- for(t=1;t<maxs;t++)
- {
- pres=currs;
- currs*=2;
-
- for(i=pres+1;i<=currs;i++)
- {
- for(j=1;j<=pres;j++)
- {
- a[i][j]=a[i-pres][j]+pres;
- }
- }
-
- for(i=1;i<=pres;i++)
- {
- for(j=pres+1;j<=currs;j++)
- {
- a[i][j]=a[i][j-pres]+pres;
- }
- }
- for(i=pres+1;i<=currs;i++)
- {
- for(j=pres+1;j<=currs;j++)
- {
- a[i][j]=a[i-pres][j-pres];
- }
- }
-
- }
-
- }
- */
- void Do(int k)
- {
- int i,j,t,n,temp;
- n=2;
- a[1][1]=1;
- a[1][2]=2;
- a[2][1]=2;
- a[2][2]=1;
- for(t=1;t<k;t++)
- {
- temp=n;
- n=n*2;
-
- 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][j-temp]+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(void) {
- int maxs;
- int n,i,j;
- scanf("%d",&n);
- maxs=pow(2,n);
- Do(maxs);
- for(i=1;i<=maxs;i++)
- {
- for(j=1;j<=maxs;j++)
- {
- printf("%d ",a[i][j]);
- }
- putchar('\n');
- }
-
- return 0;
- }
复制代码
|
|