题解:

  一定有人获胜,非黑即白;获胜条件为:black是由 上走到下,white是由 左走到右;

 #include <cstdio>
using namespace std;
int N;
char board[][];
const int direction[][] = {{-,-},{-,},{,-},{,},{,},{,}};
void DFS(int i, int j, char c,int &win)
{
board[i][j] = '.';
if (c == 'b' && i == N-) win = ;
if (c == 'w' && j == N-) win = ;
for (int x=; x<; ++x){
int i_next = i+direction[x][];
int j_next = j+direction[x][];
if (i_next< || i_next>=N || j_next< || j_next>=N) continue;
if (board[i_next][j_next] == c)
DFS(i_next, j_next, c, win);
}
}
int main()
{
//reopen("input.txt","rt",stdin);
int Case = ;
while (scanf("%d",&N)){
if (!N) break;
for (int i=; i<N; ++i)
scanf("%s",board[i]);
int win = ; // win=1:Black win=2:White
for (int i=; i<N; ++i)
if (board[i][] == 'w')
DFS(i, , 'w', win);
for (int j=; j<N; ++j)
if (board[][j] == 'b')
DFS(, j, 'b', win);
if (win == ) printf("%d B\n",Case++);
else printf("%d W\n",Case++);
}
return ;
}

题解:

  必有一胜,所以只判断black胜不胜就够了。black胜利的条件是能从第一行走到最后一行,white的胜利条件是能出第一列走到最后一列;

 #include <iostream>
using namespace std; const int maxn = + ; char board[maxn][maxn]; void wb(int x, int y, int n, char co)
{
if(x>= && x<n && y>= && y<n)
if(board[x][y] == co)
{
board[x][y] = '';
wb(x-, y-, n, co);
wb(x, y-, n, co);
wb(x+, y, n, co);
wb(x-, y, n, co);
wb(x, y+, n, co);
wb(x+, y+, n, co);
}
} int main()
{
int n, i, j, ans = ;
while(cin>>n && n)
{
for(i = ; i < n; i++)
for(j = ; j < n; j++)
cin >> board[i][j]; bool flag = false;
//black: first row
for(j = ; j < n; j++)
if(board[][j] == 'b')
wb(, j, n, 'b');
for(j = ; j < n; j++)
if(board[n-][j] == '')
{
cout << ++ans << " B" << endl;
flag = true;
break;
} if(flag)
continue;
else cout << ++ans << " W" << endl;
}
return ;
}

uva 260 - Il Gioco dell'X的更多相关文章

  1. L'opzione di luce del puntatore laser

    Prima di tutto, sono di buone dimensioni, non i 'mini' puntatori laser che altri stanno vendendo. È ...

  2. 【HDU5785】Interesting [Manacher]

    Interesting Time Limit: 30 Sec  Memory Limit: 256 MB[Submit][Status][Discuss] Description Input Outp ...

  3. Dell Inspiron 620 / Vostro 260 BIOS 开启 AHCI 模式

    1.Dell Vostro 260 台式机,WIN7 旗舰版   2.登陆 DELL 官方支持站点,获取 MS-A10.exe 安装文件   3.从网络中获取 AMIBCP.exe 工具,双击打开此程 ...

  4. UVA 257 - Palinwords(弦HASH)

    UVA 257 - Palinwords 题目链接 题意:输出一个文本里面的palinword,palinword的定义为.包括两个不同的回文子串,而且要求回文子串不能互相包括 思路:对于每一个单词推 ...

  5. Il laser che è chiaramente visibile

    Prima di quel tempo ho ottenuto questo potente puntatore laser 500mW, non so davvero come questo dis ...

  6. UVA 10526 - Intellectual Property (后缀数组)

    UVA 10526 - Intellectual Property 题目链接 题意:给定两个问题,要求找出第二个文本抄袭第一个文本的全部位置和长度,输出前k个,按长度从大到小先排.长度一样的按位置从小 ...

  7. 多维DP UVA 11552 Fewest Flop

    题目传送门 /* 题意:将子符串分成k组,每组的字符顺序任意,问改变后的字符串最少有多少块 三维DP:可以知道,每一组的最少块是确定的,问题就在于组与组之间可能会合并块,总块数会-1. dp[i][j ...

  8. Fast Matrix Operations(UVA)11992

    UVA 11992 - Fast Matrix Operations 给定一个r*c(r<=20,r*c<=1e6)的矩阵,其元素都是0,现在对其子矩阵进行操作. 1 x1 y1 x2 y ...

  9. IL异常处理

    异常处理在程序中也算是比较重要的一部分了,IL异常处理在C#里面实现会用到一些新的方法 1.BeginExceptionBlock:异常块代码开始,相当于try,但是感觉又不太像 2.EndExcep ...

随机推荐

  1. c语言实现BMP图像转换为灰度图

    当初是自己要装X,非要用c来写信息隐藏作业,装了X,就得付出实践.查了好久资料,到期末才把作业交了,这里总结一下. 这道题是将真彩图转换为灰度图. 关于BMP文件结构,这是困扰了我好久的问题,上网查了 ...

  2. T-SQL表联接查询

    由于实践不足,总是忘记SQL Server 联接表查询的细节,在这里记录以便查询. 一.交叉联接 交叉联接仅执行一个罗辑查询处理阶段——笛卡尔积.也就是说,将一个输入表的每一行与另一个表的所有行匹配. ...

  3. 关于URL编码/javascript/js url 编码/url的三个js编码函数

    关于URL编码/javascript/js url 编码/url的三个js编码函数escape(),encodeURI(),encodeURIComponent() 本文为您讲述关于js(javasc ...

  4. HDOJ 1266 Reverse Number(数字反向输出题)

    Problem Description Welcome to 2006'4 computer college programming contest! Specially, I give my bes ...

  5. sql server2008如何创建外键

    原文地址:http://blog.csdn.net/zuozuo1245/article/details/8644115 以前创建数据库时就是有主键的创建了主键,但是表之间的关系没有联系,要建数据库关 ...

  6. Spark standalone安装(最小化集群部署)

    Spark standalone安装-最小化集群部署(Spark官方建议使用Standalone模式)        集群规划:    主机        IP                    ...

  7. MYSQL存储过程和函数学习笔记

    学至Tarena金牌讲师,金色晨曦科技公司技术总监沙利穆课程笔记的综合. 1. 什么是存储过程和函数 将SQL语句放入一个集合里,然后直接调用存储过程和函数来执行已经定义好的SQL语句,通过存储过程和 ...

  8. FilterDispatcher 的作用(struts2.1.3以前,新版本改了)

    org.apache.struts2.dispatcher.FilterDispatcher是Struts2的主要的Filter,负责四个方面的功能: (1)执行Actions (2)清除Action ...

  9. 10个利用Eclipse调试Java的常见技巧

    http://www.open-open.com/news/view/1ad9099 阅读目录 1. Conditional Breakpoint 2. Exception Breakpoint 3. ...

  10. C++ 用libcurl库进行http通讯网络编程[转]

    http://www.cnblogs.com/moodlxs/archive/2012/10/15/2724318.html 目录索引: 一.LibCurl基本编程框架 二.一些基本的函数 三.cur ...