Codeforces Round #390 (Div. 2) B
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
xx..
.oo.
x...
oox.
YES
x.ox
ox..
x.o.
oo.x
NO
x..x
..oo
o...
x.xo
YES
o.x.
o...
.x..
ooxx
NO
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn.
题意:在空白出下‘x’,如果是连续的三个x(水平和垂直,对角线)就算胜利
解法:暴力判断
1 #include<bits/stdc++.h> 2 typedef long long LL; 3 typedef unsigned long long ULL; 4 using namespace std; 5 const int maxn=1e5; 6 char Mp[10][10]; 7 int solve(){ 8 for(int i=1;i<=4;i++){ 9 for(int j=1;j<=4;j++){ 10 if(Mp[i][j]=='x'&&Mp[i][j+1]=='x'&&Mp[i][j+2]=='x'&&j+2<=4){ 11 return 1; 12 } 13 } 14 } 15 for(int i=1;i<=4;i++){ 16 for(int j=1;j<=4;j++){ 17 if(Mp[i][j]=='x'&&Mp[i+1][j]=='x'&&Mp[i+2][j]=='x'&&i+2<=4){ 18 return 1; 19 } 20 } 21 } 22 for(int i=1;i<=4;i++){ 23 for(int j=1;j<=4;j++){ 24 if(Mp[i][j]=='x'&&Mp[i+1][j+1]=='x'&&Mp[i+2][j+2]=='x'&&i+2<=4&&j+2<=4){ 25 return 1; 26 } 27 } 28 } 29 for(int i=1;i<=4;i++){ 30 for(int j=1;j<=4;j++){ 31 if(Mp[i][j]=='x'&&Mp[i+1][j-1]=='x'&&Mp[i+2][j-2]=='x'&&i+2<=4&&j-2>=1){ 32 return 1; 33 } 34 } 35 } 36 return 0; 37 } 38 int main(){ 39 for(int i=1;i<=4;i++){ 40 for(int j=1;j<=4;j++){ 41 cin>>Mp[i][j]; 42 } 43 } 44 for(int i=1;i<=4;i++){ 45 for(int j=1;j<=4;j++){ 46 if(Mp[i][j]=='.'){ 47 Mp[i][j]='x'; 48 if(solve()){ 49 cout<<"YES"<<endl; 50 return 0; 51 } 52 Mp[i][j]='.'; 53 } 54 } 55 } 56 cout<<"NO"<<endl; 57 return 0; 58 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
2016-07-24 Codeforces Round #364 (Div. 2) C