杭州笕桥网站建设,营销型wordpress模板,aso优化排名,企查查在线查询来自-赦免战俘 - 洛谷
参考#xff1a;题解 P5461 【赦免战俘】 - 洛谷专栏
代码#xff1a;
#include iostream
#include math.h //利用pow()函数算次方
using namespace std;
int a[1500][1500]; //因为最大每边顶多有2^101024人#xff0c;所以1500…来自-赦免战俘 - 洛谷
参考题解 P5461 【赦免战俘】 - 洛谷专栏
代码
#include iostream
#include math.h //利用pow()函数算次方
using namespace std;
int a[1500][1500]; //因为最大每边顶多有2^101024人所以1500大小没问题定义为全局变量是为了方便使用
//全局变量会初始化为0,0就0吧当做0为还未赦免的
void ff(int x, int m, int n)
{ //x为正方形边长m和n为开始横纵坐标if (x 1) //当发现只剩一人时函数结束{return;}int i 0;int j 0;for ( i m; i mx/2; i) //由提议可以写出i与j正方形横纵的范围{for ( j n; j nx/2; j){a[i][j] 1; //注意这里先把1当做赦免的0当做未赦免的}}ff(x/2,m,nx/2); //右上角ff(x/2,mx/2,n); //左下角ff(x/2,mx/2,nx/2); //右下角}int main()
{int n;cin n;int num pow(2, n); //算2的n次方ff(num,0,0); //调用函数此函数用来给二维数组填东西for (int i 0; i num; i){for (int j 0; j num; j) //遍历输出数组{if (a[i][j] 1) //因为题意中0为赦免的1为未赦免而我之前将1当做赦免0当做未赦免。所以要将0和1换回来{a[i][j] 0;}else if (a[i][j] 0){a[i][j] 1;}cout a[i][j] ;}cout \n;}return 0;
}