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 ;
}

【HDOJ】2699 Five in a Row的更多相关文章

  1. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  2. 【C#】【MySQL】C# 查询数据库语句@Row:=@Row+1

    如何实现数据库查询产生虚拟的一列序号的功能: ) )AS r; 该语句可以实现产生虚拟的一列数据在MySQL中运行没有问题. 但是在C#里面调用去出现了错误"Parameter '@ROW' ...

  3. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  4. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  5. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

  6. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

  7. 【HDOJ】【3415】Max Sum of Max-K-sub-sequence

    DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...

  8. 【HDOJ】【3530】Subsequence

    DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...

  9. 【HDOJ】【3068】最长回文

    Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...

随机推荐

  1. [转] Scale-up 和Scale-out的区别

    http://www.cnblogs.com/spork/archive/2009/12/29/1634766.html 来自原小站,曾经迷糊过的东西,表上来,希望对正在迷糊或即将迷糊的人有帮助. 谈 ...

  2. 阿里大于验证码发送 (ThinkPhp框架)

    1.登录平台 阿里大于2.登陆之后我们可以看到资费,使用场景等,在进入正题之前我们需要一些准备工作,首先我们先了解下短信的请求参数,在这里我们需要注意的是sms_param这个参数,在接下来我们申请短 ...

  3. ASP.NET 打包下载文件

    使用的类库为:ICSharpCode.SharpZipLib.dll 一种是打包整个文件夹,另一种是打包指定的多个文件,大同小异: using ICSharpCode.SharpZipLib.Zip; ...

  4. PHP 中xampp不能启动服务器的问题

    有时候别人电脑上面的XAMPP,你把安装文件拷贝下来后,会发现,自己的电脑上用不了 这个时候有很多种情况 1. 关闭你自己电脑上有可能暂用80端口的程序 2.D:\xampp\apache\conf\ ...

  5. datagrid后台给每列添加js方法

    protected void dgExhList_ItemDataBound(object sender, DataGridItemEventArgs e) { string param = &quo ...

  6. postgresql jsonb类型查询

    select * from (select * from ud_order where user_id=10 and status=2unionselect * from ud_order where ...

  7. TSQL Beginners Challenge 1 - Find the second highest salary for each department

    很久以前准备写的系列文章,后来因为懒一直耽搁着,今天突然决定继续下去,于是有了这篇文章,很基础,但很常用.题目描述依然拷贝.简单来说就是找出个个部门薪水排名第二的人,排名相同的要一起列出来. Intr ...

  8. Dictionary的遍历和修改

    /// <summary>        /// 初始化一个Dic        /// </summary>        public static void mainTe ...

  9. Maven搭建Spring+Struts2+Hibernate项目详解

    http://www.bubuko.com/infodetail-648898.html

  10. GCD介绍(三): Dispatch Sources

    何为Dispatch Sources         简单来说,dispatch source是一个监视某些类型事件的对象.当这些事件发生时,它自动将一个block放入一个dispatch queue ...