题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3106

对抗搜索,f[x][y][a][b][c][d]表示当前谁走,走了几步,及位置。

(因为脑残+手残+眼拙写了一坨if还瞪了好久。。。最后还是这种做法靠谱。。。

#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#define maxn 109
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define ll long long
#define inf int(1e9)
using namespace std;
int dx[]={,,-,,,,-,};
int dy[]={,,,-,,,,-};
int f[][][][][][];
int n,a,b,c,d;
int read(){
int x=,f=; char ch=getchar();
while (!isdigit(ch)) {
if (ch=='-') f=-; ch=getchar();
}
while (isdigit(ch)){
x=x*+ch-''; ch=getchar();
}
return x*f;
}
int dfs(int x,int y,int a,int b,int c,int d){
if (y>*n) return inf;
if (a==c&&b==d) {
if (x) return inf;
return ;
}
if (f[x][y][a][b][c][d]) return f[x][y][a][b][c][d];
int ans=,xx=,yy=;
if (x){
ans=inf;
rep(j,,) {
xx=c+dx[j]; yy=d+dy[j];
if (<=xx&&xx<=n&&<=yy&&yy<=n) ans=min(ans,dfs(,y+,a,b,xx,yy));
}
}
else {
rep(j,,){
xx=a+dx[j]; yy=b+dy[j];
if (<=xx&&xx<=n&&<=yy&&yy<=n) ans=max(ans,dfs(,y+,xx,yy,c,d));
}
}
ans++;
f[x][y][a][b][c][d]=ans;
return f[x][y][a][b][c][d];
}
int main(){
n=read(); a=read(); b=read(); c=read(); d=read();
if (abs(a-c)+abs(b-d)==) puts("WHITE 1");
else printf("BLACK %d",dfs(,,a,b,c,d));
return ;
}
05-04 04:46