全部评论 1

  • #define REP(i,l,r) for(int i=l;i<r;++i)

    const int dx[4]={-1,0,1,0}, dy[4]={0,1,0,-1
    };

    int ansx[6], ansy[6], ansmv[6
    ];
    int mp[7][5][7
    ], N;
    bool vis[5][7
    ];

    inline void hei(int d, int x, int y, int mv)
    {
    ansx[d]=x, ansy[d]=y, ansmv[d]=mv;
    }
    inline bool inbound(int x, int y){ return 0<=x&&x<5&&0<=y&&y<7
    ;}
    void fall(int d)
    {
    REP(i,0,5){ int sz=0
    ;
    REP(j,0,7) if
    (mp[d][i][j])
    mp[d][i][sz++]=mp[d][i][j];
    while (sz < 7) mp[d][i][sz++] = 0
    ;
    }
    }
    inline void refresh(int d)
    {
    int tim = 0
    ;
    for (bool cg = true
    ; cg;){
    cg =
    false, fall
    (d);
    REP(i,0,5) REP(j,0,7) if
    (mp[d][i][j]){
    if (i < 3
    ){
    if (mp[d][i][j]==mp[d][i+1][j]&&mp[d][i][j]==mp[d][i+2
    ][j]){
    cg = vis[i][j] = vis[i+
    1][j] = vis[i+2][j] = true
    ;
    }
    }
    if (j < 5
    ){
    if (mp[d][i][j]==mp[d][i][j+1]&&mp[d][i][j]==mp[d][i][j+2
    ]){
    cg = vis[i][j] = vis[i][j+
    1] = vis[i][j+2] = true
    ;
    }
    }
    }
    REP(i,0,5) REP(j,0,7) if (vis[i][j]) mp[d][i][j] = vis[i][j] = 0
    ;
    }
    }
    bool solve(int dep)
    {
    REP(i,0,5) REP(j,0,7) mp[dep][i][j] = mp[dep-1
    ][i][j];
    refresh
    (dep);
    if (dep == N+1
    ){
    REP(i,0,5) if (mp[dep][i][0]) return false
    ;
    return true
    ;
    }
    REP(i,0,5) REP(j,0,7) if
    (mp[dep][i][j]){
    if (i < 4 && mp[dep][i][j]!=mp[dep][i+1][j]){ // 1
    hei(dep, i, j, 1
    );
    swap(mp[dep][i][j], mp[dep][i+1
    ][j]);
    if (solve(dep+1)) return true
    ;
    swap(mp[dep][i][j], mp[dep][i+1
    ][j]);
    }
    if (i && !mp[dep][i-1][j]){ // -1
    hei(dep, i, j, -1
    );
    swap(mp[dep][i][j], mp[dep][i-1
    ][j]);
    if (solve(dep+1)) return true
    ;
    swap(mp[dep][i][j], mp[dep][i-1
    ][j]);
    }
    }
    return false
    ;
    }

    int main()
    {
    scanf("%d"
    , &N);
    REP(i,0,5) REP(j,0,9
    ){
    int

    2025-07-20 来自 甘肃

    0
首页