20分,求助
  • 板块P5461 赦免战俘
  • 楼主tm25
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/9/24 11:55
  • 上次更新2023/10/27 10:10:49
查看原帖
20分,求助
744216
tm25楼主2022/9/24 11:55

20分+最后一个tle,求助

#include<bits/stdc++.h>
using namespace std;
int a[2048][2048];
void fac(int x,int r,int c)
{
	if(x==2)
	{
		a[r][c]=0;
		return;
	}
	else
	{
		for(int i=1;i<=r+x/2-1;i++)
		{
			for(int j=1;j<=c+x/2-1;j++)
			{
				a[i][j]=0;
			}
		}
		fac(x/2,r+x/2,c);
		fac(x/2,r+x/2,c+x/2);
		fac(x/2,r,c+x/2);
	}
}
int main()
{     		
	int n,p;
	scanf("%d",&n);
	p=pow(2,n);
	for(int i=1;i<=p;i++)
	{
		for(int j=1;j<=p;j++)
		{
			a[i][j]=1;
		}
	
	}
	fac(p,1,1);
	for(int i=1;i<=p;i++)
	{
		for(int j=1;j<=p;j++)
		{
			cout<<a[i][j]<<" ";
		}
		cout<<'\n';
	}
	return 0;
}
2022/9/24 11:55
加载中...