跳到正文

题解

题解 P5461 【赦免战俘】

绝顶我为峰约 1 分钟
原文
文章信息与版本

文章信息

发布
2019年7月14日
收录
2026年11月15日
更新
2026年11月21日
篇幅
约 1 分钟
获赞
6
题目
P5461

版本

  1. v1当前

还是挺水的题目

考虑到nn很小,可以dfsdfs

可以把合适的边长每次除以二,然后判断是否在最上方的正方形,也就是x<=step>>1&&y<=step>>1x<=step>>1\&\&y<=step>>1

然后就摸你模拟就好

C++
// luogu-judger-enable-o2
#include<iostream>
using namespace std;
int n,k;
bool a[1051][1051];
bool dfs(int x,int y,int step)
{
	if(x<=step&&y<=step)//如果在左上方的正方形就被释放
		return 0;
	if(step==1)//如果不能再分就标记没有释放
		return 1;
	if(x>step)//如果不在左上角就把坐标移到坐上
		x-=step;
	if(y>step)//同理
		y-=step;
	return dfs(x,y,step>>1);//继续分
}
int main()
{
	cin>>n;
	k=1;
	while(n--)
		k<<=1;//求边长
	for(int i=1;i<=k;++i)
		for(int j=1;j<=k;++j)
			a[i][j]=dfs(i,j,k>>1);//从每个点爆搜,初始边长设成边长的一半
	for(int i=1;i<=k;++i)
	{
		for(int j=1;j<=k;++j)
			cout<<a[i][j]<<" ";//输出
		cout<<endl;
	}
	return 0;
}
原文
存档评论2 条抓取于