【HDOJ】2699 Five in a Row
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的更多相关文章
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【C#】【MySQL】C# 查询数据库语句@Row:=@Row+1
如何实现数据库查询产生虚拟的一列序号的功能: ) )AS r; 该语句可以实现产生虚拟的一列数据在MySQL中运行没有问题. 但是在C#里面调用去出现了错误"Parameter '@ROW' ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
- 【HDOJ】【3415】Max Sum of Max-K-sub-sequence
DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...
- 【HDOJ】【3530】Subsequence
DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...
- 【HDOJ】【3068】最长回文
Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...
随机推荐
- java读取redis的timeout异常
http://blog.csdn.net/shuaiokshuai/article/details/23266091 FIFO Fist-in Fisrt-out 先进先出
- 快速打出System.out.println("");
sysout---->Alt+/--->System.out.println():
- UMEditor 二次开发技术实践
许多项目都会或多或少的结合许多第三的组件,恰好,遇到了UMeditor富文本组件,因为它及其精简,功能强大,有专业团队维护,所以,我选择了它,而且它出色的完成项目中的全部功能的需求,对此,我说一下,二 ...
- c#正则表达式采集数据
protected void Page_Load(object sender, EventArgs e){ StringBuilder MyStringBuilder = new StringBuil ...
- StringHelper类,内容截取,特别适合资讯展示列表
public class StringHelper { /// <summary> /// 截字符串 /// </summary> ...
- 关于mssql数据库锁和事务隔离级别
事务隔离级别有4种,这4种级别只是对于读操作,也就是select有不同程度的支持, 读未提交:不会对事务里读出来的数据附加任何锁 读已提交:会对事务里读出来的数据附加共享锁,读完就释放共享锁,其他事务 ...
- Windows的计划任务
阅读目录 一:什么是Windows的计划任务? 二:如何设置计划任务 三:高级设置计划任务 一:什么是Windows的计划任务? 在日常的工作中,我们都有一些固定的或临时性的工作,而每次在爱机前一坐, ...
- vs2010安装路径解决不能修改的方法
环境:win7 64位 解决:网上说需要卸载以下4项 Microsoft Visual Studio Tools for Applications 2.0 - ENU Microsoft Visual ...
- filter过滤器执行顺序
浏览器请求---->进入过滤器---->进入doFilter方法--->执行chain.doFilter()方法就会放行----->进入业务逻辑方法------>进入过滤 ...
- [转]iframe自适应宽度高度
<iframe id="iframe" onLoad="AutoFit();" frameborder="0" scrolling=& ...