907B - Tic-Tac-Toe
2017-12-25 19:10
375 查看
B. Tic-Tac-Toe
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.
The game is played on the following field.
Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in
some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl).
For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells
in the required field, the player can put his chip to any empty cell on any field.
You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip.
A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need
to find if the state is unreachable or not, just output possible next moves according to the rules.
Input
First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x"
(ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second
player, character "." (ASCII-code 46) describes empty cell.
The line after the table contains two integers x and y (1 ≤ x, y ≤ 9).
They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right.
It's guaranteed that cell where the last move was done is filled with "x" or "o".
Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable.
Output
Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified.
Examples
input
output
input
output
input
output
Note
In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field.
In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell.
In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable.
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.
The game is played on the following field.
Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in
some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl).
For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells
in the required field, the player can put his chip to any empty cell on any field.
You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip.
A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need
to find if the state is unreachable or not, just output possible next moves according to the rules.
Input
First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x"
(ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second
player, character "." (ASCII-code 46) describes empty cell.
The line after the table contains two integers x and y (1 ≤ x, y ≤ 9).
They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right.
It's guaranteed that cell where the last move was done is filled with "x" or "o".
Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable.
Output
Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified.
Examples
input
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... ... ... ... ... ... ... ... ... ... 6 4
output
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... !!! ... ... !!! ... ... !!! ... ...
input
xoo x.. x.. ooo ... ... ooo ... ... x.. x.. x.. ... ... ... ... ... ... x.. x.. x.. ... ... ... ... ... ... 7 4
output
xoo x!! x!! ooo !!! !!! ooo !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!!
input
o.. ... ... ... ... ... ... ... ... ... xxx ... ... xox ... ... ooo ... ... ... ... ... ... ... ... ... ... 5 5
output
o!! !!! !!! !!! !!! !!! !!! !!! !!! !!! xxx !!! !!! xox !!! !!! ooo !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!
Note
In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field.
In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell.
In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable.
题意:题是真的难读,写这么长,,还这么难理解!恶心的一币。翻译出来都还是不懂。。。。。看了别人博客就明白题意了,输入11行,包括空行,一共有9个小九宫格,
组成一个大九宫格,(就是我们玩的井字游戏看作九宫格),然后在个空格里可以下x或者O(空格是 . 符号),下了的不能在下了。在小九宫格里下的位置,把对应大九宫格的位置可以下的位置替换为"!",例如样例1,在小九宫格左下角下面下的,就把大九宫格的左下角. 替换为!。如果无法替换(替换的地方落子了)或者没有对应替换的地方,就把大九宫格全部的.替换为!,例如样例2和3.
题解:模拟替换的过程,但是难在字符串的处理和找替换的开始的行列,要找规律,用技巧。因为有空格,用gets读入行列会出错,不知道为什么。。。参考别人用getline。
还有就是不读入空格,一个一个直接读入里面的字符,最后输出自己加空格。
#include<bits/stdc++.h> using namespace std; int main() { string s[11]; int x,y,flag=0; for(int i=0; i<11; i++) ///算上空行11行 getline(cin,s[i]); ///g不知道为什么gets读入,会出问题,参考别人getline cin>>x>>y; x--,y--; ///技巧处理x,y减去一在%3,用于找需要替换开始的地方 x%=3,y%=3; ///*** int m=x*3+x,n=y*3+y;///*** for(int i=m; i<m+3; i++) ///算出的m,n就是小九宫格对应达大九宫格开始的行列 for(int j=n; j<n+3; j++) { if(s[i][j]=='.') ///(s[I][j]!='x'&&s[i][j]!='o')如果是可以落子的地方,就换成! { s[i][j]='!'; flag=1; ///如果没有可以替换的地方,就标记flag=1,全部九宫格可以落子的地方替换为! } } if(!flag) ///全部九宫格可以落子的地方替换为! { for(int i=0; i<11; i++) for(int j=0; j<11; j++) if(s[i][j]=='.') s[i][j]='!'; } for(int i=0; i<11; i++) cout<<s[i]<<endl; return 0; }
相关文章推荐
- AOJ 0066 Tic Tac Toe
- poj 2361 Tic Tac Toe
- [LeetCode] Design Tic-Tac-Toe 设计井字棋游戏
- UVA 11534 - Say Goodbye to Tic-Tac-Toe(博弈sg函数)
- 2017ACM福建省赛FZU2283 Tic-Tac-Toe
- FZU 2283 Tic-Tac-Toe (模拟)
- React 实现井字棋游戏 (tic-tac-toe) 教程 (2) <译自官方文档>
- Tic-Tac-Toe
- LightOJ 1401 No More Tic-tac-toe(SG函数)
- LeetCode "Design Tic-Tac-Toe"
- leetcode Design Tic-Tac-Toe
- Python实现的井字棋(Tic Tac Toe)游戏示例
- FZU --- 2283 Tic-Tac-Toe 【三子棋小模拟】
- React 实现井字棋游戏 (tic-tac-toe) 教程 (3) <译自官方文档>
- Codeforces Round #454 (Div. 2, based on Technocup 2018 Elimination Round 4) B - Tic-Tac-Toe
- [LeetCode] 348. Design Tic-Tac-Toe 设计井字棋游戏
- Analysis On Tic-Tac-Toe
- Android 联网 tic-tac-toe 游戏
- C - Tic-tac-toe
- 【模拟】Tic-tac-toe C…