The game ‘Il Gioco dell’ X’ is played on a N by N board (N ≥ 2). The object of both players, say Black and White, is to join opposite sides of the board by placing in turn their pawns on the board in such a way that a path is made from one side to the other by adjacent (neighboring) pawns of their own color. Although the board is N × N it is not a square but rather diamond-shaped. Let us denote the field on the board in row i and column j by (i, j) (1 ≤ i, j ≤ N). The neighbors of (i, j) are:
(i − 1, j − 1),(i − 1, j),(i, j − 1),(i, j + 1),(i + 1, j),(i + l, j + 1)
provided these fields do not fall outside the board.
    Black tries to join row 1 with row N, while White tries to join column 1 with column N.
    lt is a Deep Mathematical Result that this game cannot end in a draw (that is, without winner). As we will present to you only full boards, there will always be a winner. It may, however, be difficult to see who has won, so some computer assistance would be appreciated.
Examples:

    In example 1 White has won, and in example 2 Black has won.
Input
The input is a text file containing a number of games. Each game is given by: one line containing an integer N, being the number of rows. (N can he any number between 2 and 200). This line is followed by N lines, each consisting of a row of N characters from the set {‘b’,‘w’} denoting the pawns of Black and White respectively. The numbers of black and white pawns will differ by at most one. Note that all positions on the board are filled with pawns. The list of games ends with a single zero on a line of its own. (Of course, this is not a game for which a winner has to be determined.)
Output
The output will be a textfile containing one line for each game. This line should contain the number of the game (starting at 1) followed by a space, and followed by an uppercase ‘B’ if Black did win, or followed by an uppercase ‘W’ if White did win.
Sample Input
4
bbwb
wwbw
bbwb
bwww
4
bbwb
wwbw
bwwb
wwbb
0
Sample Output
1 W
2 B

问题链接:UVA260 Il Gioco dell’X
问题简述:两人轮流在n*n的平行四边形格子中放入黑白两色的棋子,如果黑色方能给创造一个从1~n行的连续线段则黑方胜,否则白方胜利。
问题分析:寻找从顶端到底端的解,黑白必有一方赢。用DFS来解决,也可以用Flood Fill算法来实现。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA260 Il Gioco dell'X */#include <bits/stdc++.h>using namespace std;const int dr[] = {-1, 0, 1, -1, 0, 1};
const int dc[] = {-1, -1, 0, 0, 1, 1};const int N = 200;
char b[N][N + 1];
int n;void dfs(int r, int c)
{if(r >= 0 && r < n && c >= 0 && c < n)if(b[r][c] == 'b') {b[r][c] = '1';for(int i = 0; i < 6; i++)dfs(r + dr[i], c + dc[i]);}
}int main()
{int k = 0;while(~scanf("%d", &n) && n) {for(int i = 0; i < n; i++)scanf("%s", b[i]);for(int i = 0; i < n; i++)if(b[0][i] == 'b') dfs(0, i);int flag = 0;for(int i = 0; i < n; i++)if(b[n - 1][i] == '1') {flag = 1;break;}printf("%d %c\n", ++k, flag ? 'B' : 'W');}return 0;
}

UVA260 Il Gioco dell‘X【DFS】相关推荐

  1. Bailian2815 城堡问题【DFS】

    2815:城堡问题 总时间限制: 1000ms 内存限制: 65536kB 描述 1 2 3 4 5 6 7 ############################# 1 # | # | # | | ...

  2. Bailian2816 红与黑【DFS】

    2816:红与黑 总时间限制: 1000ms 内存限制: 65536kB 描述 有一间长方形的房子,地上铺了红色.黑色两种颜色的正方形瓷砖.你站在其中一块黑色的瓷砖上,只能向相邻的黑色瓷砖移动.请写一 ...

  3. NUC1158 Lake Counting【DFS】

    Lake Counting 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 Due to recent rains, water has pooled ...

  4. NUC1399 Sum It Up【DFS】

    Sum It Up 时间限制: 1000ms 内存限制: 65535KB 通过次数: 1总提交次数: 1 问题描述 Given a specified total t and a list of n ...

  5. HDU1181 变形课【DFS】(废除)

    新题解参见:HDU1181 变形课[DFS+关系闭包+bitset] 变形课 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 13107 ...

  6. 【DFS】巧妙取量的倒油问题

    题目描述 [题目描述]  有三个容器,容量分别为 a,b,c(a> b > c ),一开始a装满油,现在问是否只靠abc三个容器量出k升油.如果能就输出"yes",并且 ...

  7. [kuangbin]专题三 Dancing Links Squiggly Sudoku HDU - 4069【DFS】【精确覆盖】

    [题目描述] Today we play a squiggly sudoku, The objective is to fill a 9*9 grid with digits so that each ...

  8. 【DFS】不撞南墙不回头—深度优先搜索算法[Deep First Search]

    今天上午听到,那个非常6+1的李咏先生因癌症去世 DFS算法的基本模型 深度下,不撞南墙不回头,就是一直往后找,知道没有路了,向后返回. 想起一首民谣,<可能否>--木小雅 https:/ ...

  9. NUC1333 Knight Moves【DFS】

    Knight Moves 时间限制: 1000ms 内存限制: 65535KB 问题描述 A friend of you is doing research on the Traveling Knig ...

最新文章

  1. 过度沉思_从沉思到演出:我如何开始我的自由职业
  2. GCD的其他(不常用)方法
  3. 【正一专栏】读《艾思奇哲学文选第六卷》
  4. SQL语法之基础查询(进阶1)and条件查询(进阶2)
  5. 网易云音乐的算法有什么特点_当算法设计音乐厅时会发生什么?
  6. R语言学习笔记(四)参数估计
  7. gradle mysql依赖关系,如何在gradle中找到\删除未使用的依赖关系
  8. Https iOS需要做的事
  9. 定制你自己的CRF模型以及JAVA实现的Word2Vec模型和一些java版NLP的工具
  10. Python之父加入微软,一开口就知道是老“凡学家”了
  11. ELK详解(二十三)——elastalert告警优化
  12. 190106每日一句
  13. jQuery百家姓验证
  14. 企业微信自建应用 网页授权登录 获取用户信息
  15. Linux中执行shell脚本的方法,在Linux中执行Shell脚本的4种方法的总结
  16. signature=461282e191fe3d72a8b43e5b831644fb,Proposed Graphene Nanospaser
  17. Nepxion Discovery(2) 全链路条件蓝绿发布
  18. 如何使用NSOperations和NSOperationQueues
  19. 【ParaView教程】2.13 保存截图和保存动画
  20. 'Periodic workspace save .' has encountered a problem

热门文章

  1. jqGrid获取数据库数据的方式
  2. 技术篇-符号制作-线符号制作
  3. 全面使用禅道做敏捷开发的规范化管理分享
  4. linux systemd命令,systemd命令
  5. C++ Memory_order的理解
  6. Git Tag 使用
  7. 微服务笔记(二) 服务发现
  8. 在计算机里分数线怎么表示什么意思,高考投档分数线是什么意思 怎么定的
  9. LeetCode 513. 找树左下角的值(递归)
  10. gstreamer的rtsp推流(笔记)