wa了几次,至少要考虑4个方向:下、右、左下、右下。很像当年北航的机试题目。

 /* 2699 */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
using namespace std; #define MAXN 16 typedef struct node_t {
char x, y, d, c;
bool f;
node_t() {}
node_t(char xx, char yy, char dd, char cc, bool ff) {
x = xx; y = yy; d = dd; c = cc; f = ff;
}
} node_t; char map[MAXN][MAXN];
char n = ;
char ch;
char dir[][] = {
// right, down, diag(2)
, , ,, , , ,-
}; bool check(char x, char y) {
return x< || x>=n || y< || y>=n;
} bool bfs(char xx, char yy) {
queue<node_t> Q;
node_t nd;
char i, j, k;
char x, y; for (i=; i<; ++i) {
nd.x = xx + dir[i][];
nd.y = yy + dir[i][];
nd.d = i;
nd.c = ;
if (check(nd.x, nd.y))
continue;
if (map[nd.x][nd.y] == ch) {
nd.f = false;
Q.push(nd);
x = xx - dir[i][];
y = yy - dir[i][];
if (!check(x, y) && map[x][y]=='.') {
nd.f = true;
nd.c = ;
Q.push(nd);
}
} else if (map[nd.x][nd.y] == '.') {
nd.f = true;
Q.push(nd);
}
} while (!Q.empty()) {
nd = Q.front();
Q.pop();
if (nd.c==) {
return true;
}
nd.x += dir[nd.d][];
nd.y += dir[nd.d][];
if (check(nd.x, nd.y))
continue;
--nd.c;
if (map[nd.x][nd.y] == ch) {
Q.push(nd);
} else if (map[nd.x][nd.y]=='.' && nd.f==false){
nd.f = true;
Q.push(nd);
}
} return false;
} int main() {
int t, tt=;
int w, b;
char i, j, k;
bool flag; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif scanf("%d", &t);
while (t--) {
w = b = ;
for (i=; i<n; ++i) {
scanf("%s", map[i]);
for (j=; j<n; ++j) {
if (map[i][j] == 'W')
++w;
else if (map[i][j] == 'B')
++b;
}
}
ch = (w==b) ? 'B' : 'W';
flag = false;
for (i=; i<n; ++i) {
for (j=; j<n; ++j) {
if (map[i][j]==ch && bfs(i,j)) {
flag = true;
goto _output;
}
}
}
_output:
if (flag)
puts("YES");
else
puts("NO");
} return ;
}

最新文章

  1. thinkphp一句话疑难解决笔记 2
  2. 从零开始攻略PHP(7)——面向对象(上)
  3. 简单的gulpfile.js参数配置
  4. win7 桌面上的网络邻居不见了
  5. jquery实现返回基部案例效果
  6. Longest Common Subsequence &amp; Substring &amp; prefix
  7. 九度OJ1081
  8. Web API入门指南(安全)转
  9. WCF获取客户端IP和端口
  10. UPDATE sql 优化
  11. uml(1)--概述
  12. 那些年,我们不懂的却又不得不提的 JAVA异常和异常处理!
  13. 201521123095 《Java程序设计》第10周学习总结
  14. 非对称加密, 助记词, PIN, WIF
  15. 咏南中间件支持JWT TOKEN
  16. CentOS6.8搭建rabbitmq消息中间件
  17. socket编程的同步、异步与阻塞、非阻塞示例详解
  18. ECMAScript6新特性之继承
  19. SqlSugarClientHelper
  20. Spring MVC处理响应的 header

热门文章

  1. css选择器优化
  2. c读mysql产生乱码问题
  3. IIS 64位上發佈32位asp.net設置
  4. ios strong weak 的区别 与 理解
  5. 十三、C# 事件
  6. Spring配置多数据源错误总结
  7. Git 基础再学习之:git checkout -- file
  8. npm不能安装任何包,报错:npm WARN onload-script failed to require onload script npm-autoinit/autoinit及解决方法
  9. [转载]hadoop SecondNamenode详解
  10. get方式编码问题解决方案 转载