C++递归,全部TLE ,是不是递归出口错了,哪位大佬给我改改
查看原帖
C++递归,全部TLE ,是不是递归出口错了,哪位大佬给我改改
341644
un_dauant楼主2023/2/14 17:38
#include <algorithm>
#include<bits/stdc++.h>
#include <cmath>
#include <csetjmp>
#include <cstring>
using namespace std;
const int maxn = 1025;
int vis[maxn][maxn];
//递归
void flag(int x1,int y1 , int x2 , int y2 ){
    if( x2 == x1 ==1 && y2 == y1){
        return;
    }
    for(int i = x1 ;i < (x1+x2)/2 ; i++){
        for(int j = y1 ;j < (y1+y2)/2 ; j++){
            vis[i][j] = 1;
        }
    }
    //cout << (x1+x2)/2<<" "<<(y1+y2)/2<<" " <<x2<<" "<<y2 << "\n";
    flag((x1+x2)/2, (y1+y2)/2,x2,y2);
    flag(x1,(y1+y2)/2,(x1+x2)/2,y2);
    flag((x1+x2)/2,y1, x2,(y1+y2)/2);
}
int main()
{
    int n;
    cin >> n;
    int size = pow(2,n);
    memset(vis,0,sizeof(vis));
    flag(0,0,size,size);
    for(int i = 0 ; i< size ; i++){
        for(int j = 0 ; j < size ; j++){
            if(vis[i][j] == 0){
                cout << 1;
            }else{
                cout << 0;
            }
            if(j!=size-1) cout <<" ";
            else{
                cout <<"\n";
            }
        } 
    }
    return 0;
}
2023/2/14 17:38
加载中...