Help! 84pts, #2 WA

P1228 地毯填补问题

IamCXK @ 2023-03-08 10:28:15

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int num = 1;
int Board[1030][1030]= {0};
int visit[1030][1030]= {0};

typedef struct tile
{
    int xx;
    int yy;
    int code;
    int n;
};

tile tt[1000005];

int tnum = 0;

bool cmp(tile x, tile y)
{
    return x.n < y.n;
}

void ChessBoard(int tr, int tc, int dr, int dc, int size)
{
    if(size == 1)
        return;
    int t = num++;
    int s = size / 2;
    //特殊方块在不在左上角
    if(dr < tr + s && dc < tc + s)
        ChessBoard(tr, tc, dr, dc, s);
    else
    {
        Board[tr+s-1][tc+s-1] = t;
        ChessBoard(tr, tc, tr+s-1, tc+s-1, s);
    }
    //特殊方块在不在右上角
    if(dr < tr + s && dc >= tc + s)
        ChessBoard(tr, tc+s, dr, dc, s);
    else
    {
        Board[tr+s-1][tc+s] = t;
        ChessBoard(tr, tc+s, tr+s-1, tc+s, s);
    }
    //特殊方块在不在左下角
    if(dr >= tr + s && dc < tc + s)
        ChessBoard(tr+s, tc, dr, dc, s);
    else
    {
        Board[tr+s][tc+s-1] = t;
        ChessBoard(tr+s, tc, tr+s, tc+s-1, s);
    }
    //特殊方块在不在右下角
    if(dr >= tr + s && dc >= tc + s)
        ChessBoard(tr+s, tc+s, dr, dc, s);
    else
    {
        Board[tr+s][tc+s] = t;
        ChessBoard(tr+s, tc+s, tr+s, tc+s, s);
    }
}
int main()
{
    int k, x, y;
    cin>>k>>x>>y;
    ChessBoard(0, 0, x-1, y-1, pow(2, k));
    for(int i=0; i<pow(2, k); i++)
    {
        for(int j=0; j<pow(2, k); j++)
        {
            if(Board[i+1][j] == Board[i][j] && Board[i+1][j+1] == Board[i][j] && visit[i][j] == 0)
            {
                tt[tnum].xx = i+2;
                tt[tnum].yy = j+1;
                tt[tnum].code = 2;
                tt[tnum].n = Board[i][j];
                visit[i][j] = 1;
                visit[i+1][j] = 1;
                visit[i+1][j+1] = 1;
                tnum++;
            }
            else if(Board[i][j+1] == Board[i][j] && Board[i+1][j+1] == Board[i][j] && visit[i][j] == 0)
            {
                tt[tnum].xx = i+1;
                tt[tnum].yy = j+2;
                tt[tnum].code = 3;
                tt[tnum].n = Board[i][j];
                visit[i][j] = 1;
                visit[i][j+1] = 1;
                visit[i+1][j+1] = 1;
                tnum++;
            }
            else if(j != 0 && Board[i+1][j] == Board[i][j] && Board[i+1][j-1] == Board[i][j] && visit[i][j] == 0)
            {
                tt[tnum].xx = i+2;
                tt[tnum].yy = j+1;
                tt[tnum].code = 1;
                tt[tnum].n = Board[i][j];
                visit[i][j] = 1;
                visit[i+1][j] = 1;
                visit[i+1][j-1] = 1;
                tnum++;
            }
            else if(Board[i][j+1] == Board[i][j] && Board[i+1][j] == Board[i][j] && visit[i][j] == 0)
            {
                tt[tnum].xx = i+1;
                tt[tnum].yy = j+1;
                tt[tnum].code = 4;
                tt[tnum].n = Board[i][j];
                visit[i][j] = 1;
                visit[i][j+1] = 1;
                visit[i+1][j] = 1;
                tnum++;
            }
            else
                continue;
        }
    }
    sort(tt, tt+tnum, cmp);
    for(int i=0; i<tnum; i++)
        cout<<tt[i].xx<<' '<<tt[i].yy<<' '<<tt[i].code<<endl;
    return 0;
}

|