求修改

P1228 地毯填补问题

htb123456 @ 2024-07-19 09:31:19

#include<bits/stdc++.h>
using namespace std;
int vx[5]={0,1,1,0,0};
int vy[5]={0,1,0,1,0};
void print(int k,int dx,int dy,int t){
    int v=1<<(k-1);
    cout<<dx+v+vx[t]<<' '<<dy+v+vy[t]<<endl;
}
void sovel(int k,int dx,int dy,int x,int y){
    int v=1<<(k-1),t;
    if(x<=v)t=(y<=v)?1:2;
    else t=(y<=v)?1:2;
    print(k,dx,dy,t);
    if(k==1)return;
    if(t==1){
        sovel(k-1,dx,dy,x,y);
        sovel(k-1,dx,dy+v,v,1);
        sovel(k-1,dx+v,dy,1,y);
        sovel(k-1,dx+v,dy+v,1,1);
    }else if(t==2){
        sovel(k-1,dx,dy,v,v);
        sovel(k-1,dx+v,dy,x,y-v);
        sovel(k-1,dx,dy+v,1,y);
        sovel(k-1,dx+v,dy+v,1,1);
    }else if(t==3){
        sovel(k-1,dx,dy,v,v);
        sovel(k-1,dx+v,dy,v,1);
        sovel(k-1,dx,dy+v,x-v,y);
        sovel(k-1,dx+v,dy+v,1,1);
    }else if(t==4){
        sovel(k-1,dx,dy,v,v);
        sovel(k-1,dx,dy+v,v,1);
        sovel(k-1,dx+v,dy,1,y);
        sovel(k-1,dx+v,dy+v,x-v,y-v);
    }
} 
int main(){
    int k,x,y;
    cin>>k>>x>>y;
    sovel(k,0,0,x,y);
    return 0;
}

|