【CodeForces-825B】解题报告(模拟,五子棋)
原始题目
B. Five-In-a-Row
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately.
Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal.
Input
You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell.
It is guaranteed that in the current arrangement nobody has still won.
Output
Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.
Examples
input
XX.XX.....
.....OOOO.
..........
..........
..........
..........
..........
..........
..........
..........
output
YES
input
XXOXX.....
OO.O......
..........
..........
..........
..........
..........
..........
..........
..........
output
NO
题目大意
给定一个五子棋棋盘,判断X棋一步之后能否胜利。
解题思路
没什么,自己写模拟。遍历每个可下的点判断横竖和斜方向上能否实现大于等于五子相连。
注意边界问题,可以采用左右上下各拓展4行4列。
解题代码
1 |
|
总结与反思
模拟的时候要注意细节,尽量不要返工。
能简化的简化(后面会学到剪纸),比如判定周围一圈没有棋子可以直接continue跳过该循环。
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!