c++28分求大佬调qwq

P1228 地毯填补问题

sakura_21 @ 2024-07-10 11:57:07

#include<bits/stdc++.h>
#define int long long
using namespace std;
int k,xx,yy;
void dt(int k,int x,int y,int u,int l)
{
    if (k==0)return ;
    if (k==1)
    {
        if (x==u&&y==l)
        {
            cout<<u+1<<" "<<l+1<<" 1"<<endl;
        }
        else if (x==u&&y==l+1)
        {
            cout<<u+1<<" "<<l<<" 2"<<endl;
        }
        else if (x==u+1&&y==l)
        {
            cout<<u<<" "<<l+1<<" 3"<<endl;
        }
        else if (x==u+1&&y==l+1)
        {
            cout<<u<<" "<<l<<" 4"<<endl;
        }
        return ;
    }
    else//void dt(int k,int x,int y,int u,int l)
    {
        int h=u+pow(2,k-1)-1,s=l+pow(2,k-1)-1;
        if (x<=h&&y<=s)

        {
            cout<<h+1<<" "<<s+1<<" 1"<<endl;
            dt(k-1,x,y,u,l);
            dt(k-1,h,s+1,u,s+1);
            dt(k-1,h+1,s,h+1,l);
            dt(k-1,h+1,s+1,h+1,s+1);
            return ;
        }

        else if (x<=h&y>s)
        {
            cout<<h+1<<" "<<s<<" 2"<<endl;
            dt(k-1,h,s,u,l);
            dt(k-1,x,y,u,s+1);
            dt(k-1,h+1,s,h+1,l);
            dt(k-1,h+1,s+1,h+1,s+1);
        }

        else if (x>h&&y<=s)
        {
            cout<<h<<" "<<s+1<<" 3"<<endl;
            dt(k-1,h,s,u,l);
            dt(k-1,h,s+1,u,s+1);
            dt(k-1,x,y,h+1,l);
            dt(k-1,h+1,s+1,h+1,s+1);
        }

        else if (x>h&&y>s)
        {
            cout<<h<<" "<<s<<" 4"<<endl;
            dt(k-1,h,s,u,l);
            dt(k-1,h,s+1,u,s+1);
            dt(k-1,h+1,s,h+1,l);
            dt(k-1,x,y,s+1,h+1);
        }
        return ;
    }
}
signed main()
{
    cin>>k;
    cin>>xx>>yy;
    dt(k,xx,yy,1,1);
    return 0;
}

by __Florie_ @ 2024-07-10 15:18:03

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ldb long double

int k,x,y,a[1030][1030];
void work(int x1,int x2,int y1,int y2,int x,int y){
    int midx=(x1+x2)>>1,midy=(y1+y2)>>1;
    if(x<=midx)
    {
        if(y<=midy)
        {
            printf("%d %d %d\n",midx+1,midy+1,1);
            if(x2-x1>=3)
            {
                work(x1,midx,y1,midy,x,y);work(x1,midx,midy+1,y2,midx,midy+1);
                work(midx+1,x2,y1,midy,midx+1,midy);work(midx+1,x2,midy+1,y2,midx+1,midy+1);
            }
        }
        else
        {
            printf("%d %d %d\n",midx+1,midy,2);
            if(x2-x1>=3)
            {
                work(x1,midx,y1,midy,midx,midy);work(x1,midx,midy+1,y2,x,y);
                work(midx+1,x2,y1,midy,midx+1,midy);work(midx+1,x2,midy+1,y2,midx+1,midy+1);
            }
        }
    }
    else
    {
        if(y<=midy)
        {
            printf("%d %d %d\n",midx,midy+1,3);
            if(x2-x1>=3)
            {
                work(x1,midx,y1,midy,midx,midy);work(x1,midx,midy+1,y2,midx,midy+1);
                work(midx+1,x2,y1,midy,x,y);work(midx+1,x2,midy+1,y2,midx+1,midy+1);
            }
        }
        else
        {
            printf("%d %d %d\n",midx,midy,4);
            if(x2-x1>=3)
            {
                work(x1,midx,y1,midy,midx,midy);work(x1,midx,midy+1,y2,midx,midy+1);
                work(midx+1,x2,y1,midy,midx+1,midy);work(midx+1,x2,midy+1,y2,x,y);
            }
        }
    }
}

int main(){
    cin>>k>>x>>y;
    int kk=pow(2,k);
    work(1,kk,1,kk,x,y);
    return 0;
}

by sakura_21 @ 2024-07-10 15:58:02

@_Florie 大佬求调qwq


|