86-不存在的AC (WA on #6求助)

P1228 地毯填补问题

star_fish @ 2024-12-17 20:29:31

大概思路类似这篇题解

不同点在于放置地毯时通过缩小范围递归寻找公主所在位置

通过了教练造的数据 洛谷WA一个点

求一份hack数据 如果能帮忙调代码就更好了

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 500500
int a[N],ans,n,x,k,y;
int _2pow[11]={1,2,4,8,16,32,64,128,256,512,1024};
int fl;//需要填补的地毯类型
void place(int i,int j,int fl){cout<<i<<' '<<j<<' '<<fl<<'\n';}
void work(int fl,int k,int x,int y){
    //在(x,y)放一个规模为2^k的kind型地毯
    if(k==1){
        place(x,y,fl);
        return ;
    } 
    if(fl==1){
        work(3,k-1,x-_2pow[k]+1,y);
        work(2,k-1,x,y-_2pow[k]+1);
        work(1,k-1,x,y);
        work(1,k-1,x-_2pow[k-2],y-_2pow[k-2]);
    }
    else if(fl==2){
        work(4,k-1,x-_2pow[k]+1,y);
        work(1,k-1,x,y+_2pow[k]-1);
        work(2,k-1,x,y);
        work(2,k-1,x-_2pow[k-2],y+_2pow[k-2]);
    }
    else if(fl==3){
        work(4,k-1,x,y-_2pow[k]+1);
        work(1,k-1,x+_2pow[k]-1,y);
        work(3,k-1,x,y);
        work(3,k-1,x+_2pow[k-2],y-_2pow[k-2]);
    }
    else {
        work(3,k-1,x,y+_2pow[k]-1);
        work(2,k-1,x+_2pow[k]-1,y);
        work(4,k-1,x,y);
        work(4,k-1,x+_2pow[k-2],y+_2pow[k-2]);
    }
}
void find(int nx,int ny,int k){
    int len=_2pow[k-1],l2=_2pow[k]-1;
    if(nx==x&&ny==y) return ;
    if(x>nx-len&&y>ny-len){
        find(nx,ny,k-1); 
        work(4,k,nx-l2,ny-l2);
    }
    if(x>nx-len&&y<=ny-len){
        find(nx,ny-len,k-1); 
        work(3,k,nx-l2,ny);
    }
    if(x<=nx-len&&y>ny-len){
        find(nx-len,ny,k-1); 
        work(2,k,nx,ny-l2);
    }
    if(x<=nx-len&&y<=ny-len){
        find(nx-len,ny-len,k-1); 
        work(1,k,nx,ny);
    }

} 
signed main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>k>>x>>y;
    int l=_2pow[k];
    find(l,l,k);
    return 0;
}

|