Luo Gu [P4576] board game

topic

Topic link: https://www.luogu.com.cn/problem/P4576
a \ (n * n (n \ geq 2) \) have each a child of Othello on the board. Player A and B in turn move the pieces, A go.

  • A movement of rules: can only move white stones. It may be one of four directions, both horizontally and a moving grid.
  • Mobile Rule B: You can only move the black pieces. A cell can be moved up at one or two cells both horizontally and vertically.

And the usual "eating child" rules, when a player to move their pieces to the other pieces where the grid when he won.
Two players are very clever, when you can win would win as soon as possible, only to lose when will try to stall for time. Your task is to determine who would win, how many rounds need.
For example \ (n-2 = \) , white stones in \ ((1,1) \) , black stones in \ ((2, 2) \) , then there are two moves while A, B Total second round You can win.

Ideas:

First obvious point is that, absent a draw and win if and only if A beginning albino with sunspots on adjacent.
If not, then that B win. At this point we just want to win as soon as possible B, A time to try to drag.
Set \ (f [i] [j ] [k] [l] [dep] \) represents albino in \ ((I, J) \) , sunspots \ ((K, L) \) , has gone \ (dep \) time steps, sunspot minimum number of steps needed to win to go.
So albino transferred from four directions and come, take \ (max \) value; sunspot up and down up and down from side to side transfer and come, take (?) \ (Min \) value.
Search can remember.
So the border is how much?
Here are gained a more method (
We can manually dichotomy \ (dep \) maximum \ (MAXN \) , if \ (dep> maxn \) no longer search for it.
Enumeration albino point of each of sunspots and, then \ (ANS \) recorded in the search depth is not more than \ (MAXN \) in the case where the \ (max (Solve (I, J, K, L)) \) , wherein \ (solve (i, j, k, l) \) is when the white spots \ ((I, J) \) , black dots ((k, l) \) \ , the sunspots winning the minimum number of steps .
If \ (ANS = MAXN + 1 \) , then it shows the depth of \ (maxn \) is not enough, or sufficient.
Measured up to answer \ (58 \) , so the search \ (60 \) layer is enough.

Code

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N=25,MAXN=90,Inf=1e9;
const int dx[]={0,0,0,-1,1,0,0,-2,2};
const int dy[]={0,1,-1,0,0,-2,2,0,0};
int n,sx,sy,tx,ty,f[N][N][N][N][MAXN];

int dfs(int x,int y,int xx,int yy,int dep)
{
    if (xx==x && yy==y) return (dep&1) ? Inf : 0;
    if (dep>60) return (dep&1) ? 0 : Inf;
    if (f[x][y][xx][yy][dep]) return f[x][y][xx][yy][dep];
    if (dep&1)
    {
        f[x][y][xx][yy][dep]=Inf;
        for (register int i=1;i<=8;i++)
            if (xx+dx[i]>=1 && xx+dx[i]<=n && yy+dy[i]>=1 && yy+dy[i]<=n)
                f[x][y][xx][yy][dep]=min(f[x][y][xx][yy][dep],dfs(x,y,xx+dx[i],yy+dy[i],dep+1)+1);
    }
    else
        for (register int i=1;i<=4;i++)
            if (x+dx[i]>=1 && x+dx[i]<=n && y+dy[i]>=1 && y+dy[i]<=n)
                f[x][y][xx][yy][dep]=max(f[x][y][xx][yy][dep],dfs(x+dx[i],y+dy[i],xx,yy,dep+1)+1);
    return f[x][y][xx][yy][dep];
}

int main()
{
    scanf("%d%d%d%d%d",&n,&sx,&sy,&tx,&ty);
    for (register int i=1;i<=4;i++)
        if (sx+dx[i]==tx && sy+dy[i]==ty) return !printf("WHITE 1");
    printf("BLACK %d",dfs(sx,sy,tx,ty,0));
    return 0;
}

Guess you like

Origin www.cnblogs.com/stoorz/p/12117027.html