14分求调

P1228 地毯填补问题

wangif424 @ 2022-09-17 16:56:00

#include<bits/stdc++.h>
using namespace std;
struct dt{
    int x,y,type;
};
queue<dt> ditan;
void push(int x,int y,int c){
    dt a;
    a.type=c;
    a.x=x;
    a.y=y;
    ditan.push(a);
    return;
}
void f(int k,int x,int y,int gx,int gy){
    if(k==1){
        if(x==gx && y==gy){
            push(x+1,y+1,1);
        }else if(x+1==gx && y+1==gy){
            push(x,y,4);
        }else if(x+1==gx && y==gy){
            push(x,y+1,3);
        }else if(x==gx && y+1==gy){
            push(x+1,y,2);
        }
    }else{
        int l=1<<k;
        int mid=l>>1;
        if(x+mid-1 >= gx && y+mid-1 >=gy){
            push(x+mid,y+mid,1);
            f(k-1,x,y,gx,gy);
            f(k-1,x,y+mid,x+mid-1,y+mid);
            f(k-1,x+mid,y,x+mid,y+mid-1);
            f(k-1,x+mid,y+mid,x+mid,y+mid);
        }else if(x+mid <= gx && y+mid-1>=gy){
            push(x+mid-1,y+mid,3);
            f(k-1,x,y,x+mid-1,y+mid-1);
            f(k-1,x,y+mid,x+mid-1,y+mid);
            f(k-1,x+mid,y,gx,gy);
            f(k-1,x+mid,y+mid,x+mid,y+mid);
        }else if(x+mid-1 >= gx && y+mid <= gy){
            push(x+mid,y+mid-1,2);
            f(k-1,x,y,x+mid-1,y+mid-1);
            f(k-1,x,y+mid,gx,gy);
            f(k-1,x+mid,y,x+mid,y+mid-1);
            f(k-1,x+mid,y+mid,x+mid,y+mid);
        }else{
            push(x+mid,y+mid-1,4);
            f(k-1,x,y,x+mid-1,y+mid-1);
            f(k-1,x,y+mid,x+mid-1,y+mid);
            f(k-1,x+mid,y,x+mid,y+mid-1);
            f(k-1,x+mid,y+mid,gx,gy);
        }
    }
    return;
}
int k,gx,gy;
int main(){
    cin >> k >> gx >> gy;
    f(k,1,1,gx,gy);
    while(!ditan.empty()){
        cout << ditan.front().x << " " << ditan.front().y << " " << ditan.front().type << endl;
        ditan.pop();
    }
    return 0;
}

by tatianyi @ 2023-02-18 00:03:43

55行的

push(x + mid, y + mid - 1, 4);

需要改成

push(x + mid - 1, y + mid - 1, 4);

|