28分求调

P1228 地毯填补问题

Utf8734 @ 2025-01-04 22:37:17

https://www.luogu.com.cn/record/197117362 思路同一楼题解

#include <iostream>
using namespace std;

void solve(int x, int y, int a, int b, int sze){
    int l = (sze >> 1);
    if(sze <= 1){
        return;
    }
    if(x < a + l && y < b + l){
        printf("%d %d 1\n", a + l, b + l);
        solve(x, y, a, b, l);
        solve(a + l - 1, b + l, a, b + l, l);
        solve(a + l, b + l - 1, a + l, b, l);
        solve(a + l, b + l, a + l, a + l, l);
    }else if(x < a + l && y >= b + l){
        printf("%d %d 2\n", a + l, b + l - 1);
        solve(a + l - 1, b + l - 1, a, b, l);
        solve(x, y, a, b + l, l);
        solve(a + l, b + l - 1, a + l, b, l);
        solve(a + l, b + l, a + l, b + l, l);
    }else if(x >= a + l && y < b + l){
        printf("%d %d 3\n", a + l - 1, b + l);
        solve(a + l - 1, b + l - 1, a, b, l);
        solve(a + l - 1, b + l, a, b + l, l);
        solve(x, y, a + l, b, l);
        solve(a + l, b + l, a + l, b + l, l);
    }else{
        printf("%d %d 4\n", a + l - 1, b + l - 1);
        solve(a + l - 1, b + l - 1, a, b, l);
        solve(a + l - 1, b + l, a, b + l, l);
        solve(a + l, b + l - 1, a + l, b, l);
        solve(x, y, a + l, b + l, l);
    }
}

int main(){
    int x, y, k;

    scanf("%d\n%d %d", &k, &x, &y);

    solve(x, y, 1, 1, (1 << k));

    return 0;
}

|