14pts求助,是地毯号码不对吗?本地跑是没问题的

P1228 地毯填补问题

dami826 @ 2023-08-19 15:40:56

#include<bits/stdc++.h>
using namespace std;
void carpet(int size,int carpet_x,int carpet_y,int type){
    //printf("c(%d,%d,%d,%d)\n",size,carpet_x,carpet_y,type);
    if(size==1){
        printf("%d %d %d\n",carpet_x,carpet_y,type);
        return;
    }
    switch(type){
        case 1:
            carpet(size/2,carpet_x-size/2,carpet_y-size/2,1);
            carpet(size/2,carpet_x,carpet_y,1);
            carpet(size/2,carpet_x,carpet_y-2*size+1,2);
            carpet(size/2,carpet_x-2*size+1,carpet_y,3);
            break;
        case 2:
            carpet(size/2,carpet_x-size/2,carpet_y+size/2,2);
            carpet(size/2,carpet_x,carpet_y,2);
            carpet(size/2,carpet_x-2*size+1,carpet_y,4);
            carpet(size/2,carpet_x,carpet_y+2*size-1,1);
            break;
        case 3:
            carpet(size/2,carpet_x+size/2,carpet_y-size/2,3);
            carpet(size/2,carpet_x,carpet_y,3);
            carpet(size/2,carpet_x+2*size-1,carpet_y,2);
            carpet(size/2,carpet_x,carpet_y-2*size+1,4);
            break;
        case 4:
            carpet(size/2,carpet_x+size/2,carpet_y+size/2,4);
            carpet(size/2,carpet_x,carpet_y,4);
            carpet(size/2,carpet_x,carpet_y+2*size-1,3);
            carpet(size/2,carpet_x+2*size-1,carpet_y,2);
            break;
    }
}
void princess(int size,int x,int y,int map_x,int map_y){
    //printf("p(%d,%d,%d,%d,%d)\n",size,x,y,map_x,map_y);
    if(size==1){
        return;
    }
    if(x<map_x+size/2){
        if(y<map_y+size/2){
            //cout<<"左上"<<endl; 
            princess(size/2,x,y,map_x,map_y);
            carpet(size/2,map_x+size-1,map_y+size-1,1);
        }
        else{
            //cout<<"右上"<<endl;
            princess(size/2,x,y,map_x,map_y+size/2);
            carpet(size/2,map_x+size-1,map_y,2);
        }
    }
    else{
        if(y<map_y+size/2){
            //cout<<"左下"<<endl;
            princess(size/2,x,y,map_x+size/2,map_y);
            carpet(size/2,map_x,map_y+size-1,3);
        }
        else{
            //cout<<"右上"<<endl;
            princess(size/2,x,y,map_x+size/2,map_y+size/2);
            carpet(size/2,map_x,map_y,4);
        }
    }
}
int main(){ 
    int n,x,y,size=2;
    scanf("%d\n%d %d",&n,&x,&y);
    for(int i=1;i<n;i++){
        size*=2;
    }
    princess(size,x,y,1,1);
    return 0;
}

by pineappler @ 2023-08-19 18:27:44

是的,题目给的图的顺序错了


|