题解:

  一定有人获胜,非黑即白;获胜条件为: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文件处理之文件读取方式(二)

    Python的open文件的读取方式有以下几种方法: read([size]):读取文件,如果传了size参数,则读取size字节,否则读取全部 readline([size]):读取一行 readl ...

  2. [Python 3.x 官方文档翻译]The Python Tutorial Python教程

    Python is an easy to learn, powerful programming language. It has efficient high-level data structur ...

  3. mvc4 整合nhibernate3.0配置

    鉴于大家都在解决问题或是学习新东西的时候,并不关注是谁又是谁帮你解决了问题,所有这里为自己做下宣传,我为自己代言. 首先介绍下我的开发环境是vs2010旗舰版,nhibernate采用的是3.0版本. ...

  4. PHP 访问类中的静态属性

    静态属性和普通属性不一样,静态属性只属于类本身而不属于类的任何实例,所以他们的访问方式也不一样.你可以把静态属性认为是存储在类当中的全局变量,而且你可以在任何地方通过类来访问它们. 在类本身中访问静态 ...

  5. XJOI网上同步测试DAY14 T1

    思路:线段树维护最短路 #include<cstdio> #include<cmath> #include<iostream> #include<algori ...

  6. Altium Designer 导出Gerber文件详细教程

    Altium Designer 导出Gerber文件详细教程   1.用Altium打开需要导出Gerber文件的PCB: 2.点击“File”-“fabricatio Outputs ” “Gerb ...

  7. Delphi 自带的 Base64 编解码函数

    今天帮别人解决一个关于 Base64 编解码的问题,竟然发现 Delphi 自带了 Base64 编解码的单元,叫 EncdDecd,这名字很拗口而且不直观,估计这是一直很少人关注和知道的原因. 这个 ...

  8. 如何实现室内Wi-Fi无线终端的精准定位

    如何实现室内Wi-Fi无线终端的精准定位 如何实现室内Wi-Fi无线终端的精准定位 随着商圈020的兴起,室内定位技术的也如百花争艳般不断涌现.但随着室内Wi-Fi网的架设普及,基于Wi-Fi定位技术 ...

  9. java类的加载顺序

    related URL: http://www.cnblogs.com/guoyuqiangf8/archive/2012/10/31/2748909.html Parent Class: packa ...

  10. 1346 - Songs (贪心)

    John Doe is a famous DJ and, therefore, has the problem of optimizing the placement of songs on his ...