求助!!!!!为什么只通过了一个案例,自己测试了几组数据没有问题

P1228 地毯填补问题

Titan_Hope @ 2020-08-04 22:46:10

#include<iostream>
using namespace std;
void solution(long long x,long long y,long long lx,long long ly,long long len  );
int main(void)
{
    //输入:
    int k;
    long long x,y;
    cin>>k>>x>>y;
    int len =1<<k;

    solution(3,3,1 ,1,len);
    return 0;   
} 
void solution(long long x,long long y,long long lx,long long ly,long long len  )
{
    if(len==1)return ;
    else if(lx+len/2-1>= x)//左 
    {
        if(ly+len/2-1>=y)//上 
        {
            cout<<lx+len/2<<" "<<ly+len/2<<" "<<1<<endl; 
            solution(x,y,lx,ly,len/2);//递归左上角
            solution(lx+len/2-1,ly+len/2,lx ,ly+len/2 ,len/2);//右上角
            solution(lx+len/2,ly+len/2-1,lx+len/2,ly ,len/2) ;//左下角 
            solution(lx+len/2,ly+len/2,lx+len/2,ly+len/2,len/2);//右下角 

        }
        else if(ly+len/2-1<y)
        {
            cout<<lx+len/2<<" "<<ly+len/2-1<<" "<<2<<endl;
            //遍历该方格: 

            solution(lx+len/2-1,ly+len/2-1,lx,ly ,len/2);  //左上角 
            solution(x,y,lx,ly+len/2,len/2);//右上角
            solution(lx+len/2,ly+len/2-1,lx+len/2,ly ,len/2) ;//左下角 
            solution(lx+len/2,ly+len/2,lx+len/2,ly+len/2,len/2);//右下角 
        } 
    }
    else if(lx+len/2-1<x)
    {
        if(ly+len/2-1>=y)
        {
            cout<<lx+len/2-1<<" "<<ly+len/2<<" "<<3<<endl;
            solution(lx+len/2-1,ly+len/2-1,lx,ly,len/2);
            solution(lx+len/2-1,ly+len/2,lx,ly+len/2,len/2);//右上角
            solution(x ,y,lx+len/2,ly ,len/2) ;//左下角 
            solution(lx+len/2,ly+len/2,lx+len/2,ly+len/2,len/2);//右下角
        }
        else if(ly+len/2-1<y)
        {
            cout<<lx+len/2-1<<" "<<ly+len/2-1<<" "<<4<<endl;
            solution(lx+len/2-1,ly+len/2-1,lx,ly,len/2);
            solution(lx+len/2-1,ly+len/2,lx,ly+len/2,len/2);//右上角
            solution(lx+len/2 ,ly+len/2-1,lx+len/2,ly ,len/2) ;//左下角 
            solution(x,y,lx+len/2,ly+len/2,len/2);//右下角
        }
    }
}

by Ckger @ 2020-08-04 23:21:08

唉,没救了,我太渣了,我也不会


by EgLund @ 2020-08-06 20:27:43

solution(3,3,1 ,1,len);应该是solution(x,y,1 ,1,len);吧


by EgLund @ 2020-08-06 20:42:59

至于那一个点,是因为那个点的x=3,y=3(似乎好像可能maybe差不多是样例吧)


|