Tic-Tac-Toe-(暴力模拟)
https://ac.nowcoder.com/acm/contest/847/B
#include<algorithm>
#include<cstring>
#include<iostream>
#include<math.h>
#include<string>
#include<stdio.h>
#include<map>
#include<queue>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std; char a[][];
int t; bool check()
{
int num1=,num2=;///白子数,空位数
for(int i=;i<;i++)///横的
{
num1=;num2=;
for(int j=;j<;j++)
{
if( a[i][j]=='W' )
num1++;
else if( a[i][j]=='#' )
num2++;
else
break;
}
if(num1== && num2==)
return true;
} for(int j=;j<;j++)///竖的
{
num1=num2=;
for(int i=;i<;i++)
{
if( a[i][j]=='W' )
num1++;
else if( a[i][j]=='#' )
num2++;
else
break;
}
if(num1== && num2==)
return true;
}
num1=num2=;
for(int i=;i<;i++)///左上到左下
{
if( a[i][i]=='W' )
num1++;
else if( a[i][i]=='#' )
num2++;
else
break;
}
if(num1== && num2==)
return true;
num1=num2=;
for(int i=;i<;i++)///左下到右上
{
if(i==)
{
if( a[][]=='W' )
num1++;
else if( a[][]=='#' )
num2++;
else if( a[][]=='B')
break;
}
if(i==)
{
if( a[][]=='W' )
num1++;
else if( a[][]=='#' )
num2++;
else if( a[][]=='B')
break;
}
if(i==)
{
if( a[][]=='W' )
num1++;
else if( a[][]=='#' )
num2++;
else if( a[][]=='B')
break;
}
}
if(num1== && num2==)
return true;
return false;
} int main()
{
scanf("%d",&t);
while(t--)
{
int flag;
flag=;
for(int i=;i<;i++)
scanf("%s",a[i]);
if(check())///正常情况下一步能赢
{
for(int i=;i<&&flag==;i++)
{
for(int j=;j<&&flag==;j++)
{
if( a[i][j]=='W' )
{
a[i][j]='#';
if(!check())
flag=;///存在某种情况被拿了之后不能赢
a[i][j]='W';
}
}
}
if(flag==)
printf("Alice\n");
else
printf("Emmm\n");
}
else
{
printf("Bob\n");
}
}
return ;
}
Tic-Tac-Toe-(暴力模拟)的更多相关文章
- 2019 GDUT Rating Contest III : Problem C. Team Tic Tac Toe
题面: C. Team Tic Tac Toe Input file: standard input Output file: standard output Time limit: 1 second M ...
- Principle of Computing (Python)学习笔记(7) DFS Search + Tic Tac Toe use MiniMax Stratedy
1. Trees Tree is a recursive structure. 1.1 math nodes https://class.coursera.org/principlescomputin ...
- POJ 2361 Tic Tac Toe
题目:给定一个3*3的矩阵,是一个井字过三关游戏.开始为X先走,问你这个是不是一个合法的游戏.也就是,现在这种情况,能不能出现.如果有人赢了,那应该立即停止.那么可以知道X的步数和O的步数应该满足x= ...
- 【leetcode】1275. Find Winner on a Tic Tac Toe Game
题目如下: Tic-tac-toe is played by two players A and B on a 3 x 3 grid. Here are the rules of Tic-Tac-To ...
- LeetCode 5275. 找出井字棋的获胜者 Find Winner on a Tic Tac Toe Game
地址 https://www.acwing.com/solution/LeetCode/content/6670/ 题目描述A 和 B 在一个 3 x 3 的网格上玩井字棋. 井字棋游戏的规则如下: ...
- [CareerCup] 17.2 Tic Tac Toe 井字棋游戏
17.2 Design an algorithm to figure out if someone has won a game oftic-tac-toe. 这道题让我们判断玩家是否能赢井字棋游戏, ...
- Epic - Tic Tac Toe
N*N matrix is given with input red or black.You can move horizontally, vertically or diagonally. If ...
- python 井字棋(Tic Tac Toe)
说明 用python实现了井字棋,整个框架是本人自己构思的,自认为比较满意.另外,90%+的代码也是本人逐字逐句敲的. minimax算法还没完全理解,所以参考了这里的代码,并作了修改. 特点 可以选 ...
- ACM-Team Tic Tac Toe
我的代码: #include <bits/stdc++.h> using namespace std; int main() { char a[3][3]; int i,j=0; for( ...
- bnuoj 20832 Calculating Yuan Fen(暴力模拟)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=20832 [题意]: 给你一串字符串,求一个ST(0<ST<=10000),对字符串中字符 ...
随机推荐
- C语言结构体的“继承”
这里说的继承有点像C++里的父类和子类,实际上是结构体类型的强制转换,最近看Linux内核源码时经常接触到这种方法,在这里就当作是一个简单的学习吧. 下面给出一个Demo,很简单,分别定义了一个fat ...
- pip install 时报错 pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
pip install 时报错: pip is configured with locations that require TLS/SSL, however the ssl module in Py ...
- 公众号后台开发(SpingMVC接收与响应公众号消息)
1.准备 1.准备服务 与微信对接的url要具备以下条件: (1)在公网上能够访问 (2)端口只支持80端口 在这里如果是公网能够访问的服务最好,也可以通过花生壳或者其他外网映射工具进行映射,比如ng ...
- 关于Java单例模式中双重校验锁的实现目的及原理
开始复习设计模式,一开始理解单例模式中的双重校验锁卡住了,想通了后就自己做了段思维导图来帮助自己理解. 其实理解下来并不难,但还是记录下来帮助自己回忆和借机试试养成写博客的习惯~ public cla ...
- 大一0基础小白用最基础C写哥德巴赫猜想
#include <stdio.h>int main (){ int a,b,c,k,count1,count2; for(a=4;a<=1200;a=a+2){ for(b=2;b ...
- Rsync学习之旅上
rsync 简介 什么是rsync rsync是一款开源的,快速的,多功能的,可实现全量及增量的本地或远程数据同步备份的优秀工具. 全量:将全部数据,进行传输覆盖 增量:只传输差异部分的数据 实现增量 ...
- SQL Server 连接字符串总结
这里记录的是c# 在vs中连接sql server数据库中的连接字符串的总结. 1.标准安全连接 Data Source = myServerAddress;Initial Catalog = myD ...
- C#安装和卸载windowsService的bat指令
只需新建2个文本文档,将2个指令分别复制进去,再将txt格式改为bat格式,以管理员身份运行 安装指令 %SystemRoot%\Microsoft.NET\Framework\v4.0.30319\ ...
- 【Java深入研究】11、深入研究hashmap中的hash算法
一.简介 大家都知道,HashMap中定位到桶的位置 是根据Key的hash值与数组的长度取模来计算的. JDK8中的hash 算法: static final int hash(Object key ...
- 封装axios,带请求头和响应头
import axios from "axios"; import qs from "qs"; //处理参数 import router from '../ro ...