题解:

  一定有人获胜,非黑即白;获胜条件为: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. Python自动化运维之5、内置函数

    python3.x内置函数 官网详解 一些例子:后期慢慢接触到再补充 # help() 详细查看某个类有那些方法或者方法的具体使用 >>> help(str) >>> ...

  2. oldboy第十三天学习

    1.现在给我的感觉是,python终于入门了开始越学越简单了.变得更好理解了. 一.memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它 ...

  3. 05 - 替换vtkDataObject中的Update方法 VTK 6.0 迁移

    VTK6 引入了许多不兼容的变.其中之一是删除vtkDataObject中所有有关管道的方法.下面讨论update方法并提供迁移现有代码的建议. Update() vtkDataObject::Upd ...

  4. 转:Gulp的目标是取代Grunt

    原文来自于:http://www.infoq.com/cn/news/2014/02/gulp Fractal公司积极参与了数个流行Node.js模块的开发,它最近发布了一个新的构建系统gulp,希望 ...

  5. 欧拉计划之Largest palindrome product

    A palindromic number reads the same both ways. The largest palindrome made from the product of two 2 ...

  6. USB状态错误原因

    USBD_STATUS调试过USB的同学肯定见过BUS Hound里面给的各种错误提示,但是大家是否知道是什么意思呢? USBD_STATUS 出错原因,详解如下:   The USBD_STATUS ...

  7. Basefragment的封装使用

    1.前言 封装作为面向对象的三大特性之一,在我们平时的coding过程用的那是非常的多的.大多数时候,我们可以根据封装情况评判代码的质量水平. 本文主要讲解的是fragment的封装.大体上,在项目的 ...

  8. 删除WIN7系统的共享文件

    运行里面输入fsmgmt.msc命令,点开共享目录,选定要取消共享的文件右键,停止共享.

  9. HDU_2056——相交矩形的面积

    Problem Description Given two rectangles and the coordinates of two points on the diagonals of each ...

  10. Git分支学习总结

    思维导图:        总结:        Git分支:分为2类合计为5种分支.        第一类:主分支和开发分支.        第二类:特性分支,热补丁分支,版本分支.