2015年2月6日 星期五

2013-2014 ACM ICPC Central European Regional Contest (CERC 13), problem: (F) Draughts

#include <iostream>
#include <cstdio>

using namespace std;

int Ans;
int now;

int T;
char board[20][20];

int vx[] = {-1, -1, 1, 1};
int vy[] = {1, -1, -1, 1};

void process(int x, int y)
{
    for(int vi = 0; vi < 4; vi++)
    {
        int nx = x + vx[vi]*2;
        int ny = y + vy[vi]*2;

        if( 0 > nx || nx >= 10 ) continue;
        if( 0 > ny || ny >= 10 ) continue;

        if( board[nx][ny] != '#' ) continue;
        if( board[x+vx[vi] ][y+vy[vi] ] != 'B' ) continue;

        board[x][y] = '#';
        board[x+vx[vi] ][y+vy[vi] ] = '#';
        board[nx][ny] = 'W';

        Ans = max(Ans, ++now);
        process(nx, ny);

        now--;

        board[x][y] = 'W';
        board[x+vx[vi] ][y+vy[vi] ] = 'B';
        board[nx][ny] = '#';
    }
}

int main()
{
    scanf("%d", &T);

    while( T-- )
    {
        Ans = now = 0;

        for(int i = 0; i < 10; i++)
            scanf("%s", board[i]);

        for(int i = 0; i < 10; i++)
            for(int j = 0; j < 10; j++)
                if( board[i][j] == 'W' )
                    process(i, j);

        printf("%d\n", Ans);
    }
}

沒有留言:

張貼留言