题目链接:

L - Tic-Tac-Toe

FZU - 2283

题目大意:两个人下棋,一共是三步棋,第一个人下一步,第二个人下一步,第三个人下一步,然后问你在两个人在都足够聪明的条件下,第一个人能否获胜?(获胜的前提,其中一个人的三个棋子连成了一条线)。

参考博客:

Tic-Tac-Toe FZU - 2283 (暴力) - CSDN博客

具体思路:首先必胜态一共有两种情况,一行一共有三个,存在一行有两个是第一个人的棋子,另外一个是空格,这种情况下第一个人必胜。

第二个情况,存在相交的两行,这两行都满足有一个是第一个人的棋子,剩余的两个为空格,这样也是满足的。

AC代码:

 #include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn =2e5+;
char a[][];
char u;
bool judge(int x,int y)
{
int flag1=,flag2=;
int t1=, t2=;
for(int i=; i<=; i++)
{
if(a[x][i]=='.')
t1++;
if(a[x][i]==u)
t2++;
}
if(t1==&&t2==)
flag1++;
if(t1==&&t2==)
flag2++;
t1=,t2=;
for(int i=; i<=; i++)
{
if(a[i][y]=='.')
t1++;
if(a[i][y]==u)
t2++;
}
if(t1==&&t2==)
flag1++;
if(t1==&&t2==)
flag2++;
if(x==y)
{
t1=,t2=;
for(int i=; i<=; i++)
{
if(a[i][i]=='.')
t1++;
if(a[i][i]==u)
t2++;
}
if(t1==&&t2==)
flag1++;
if(t1==&&t2==)
flag2++;
}
if(x+y==)
{
t1=,t2=;
for(int i=; i<=; i++)
{
if(a[i][+-i]=='.')
t1++;
if(a[i][-i]==u)
t2++;
}
if(t1==&&t2==)
flag1++;
if(t1==&&t2==)
flag2++;
}
return flag1>=|| flag2>=;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
for(int i=; i<=; i++)
{
for(int j=; j<=; j++)
{
scanf(" %c",&a[i][j]);
}
}
int flag=;
scanf(" %c",&u);
for(int i=; i<=; i++)
{
for(int j=; j<=; j++)
{
if(judge(i,j))
{
flag=;
break;
}
}
if(flag)
break;
}
if(flag)
printf("Kim win!\n");
else
printf("Cannot win!\n");
}
return ;
}

L - Tic-Tac-Toe FZU - 2283 (思维)的更多相关文章

  1. 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 ...

  2. POJ 2361 Tic Tac Toe

    题目:给定一个3*3的矩阵,是一个井字过三关游戏.开始为X先走,问你这个是不是一个合法的游戏.也就是,现在这种情况,能不能出现.如果有人赢了,那应该立即停止.那么可以知道X的步数和O的步数应该满足x= ...

  3. 【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 ...

  4. 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 ...

  5. [CareerCup] 17.2 Tic Tac Toe 井字棋游戏

    17.2 Design an algorithm to figure out if someone has won a game oftic-tac-toe. 这道题让我们判断玩家是否能赢井字棋游戏, ...

  6. Epic - Tic Tac Toe

    N*N matrix is given with input red or black.You can move horizontally, vertically or diagonally. If ...

  7. python 井字棋(Tic Tac Toe)

    说明 用python实现了井字棋,整个框架是本人自己构思的,自认为比较满意.另外,90%+的代码也是本人逐字逐句敲的. minimax算法还没完全理解,所以参考了这里的代码,并作了修改. 特点 可以选 ...

  8. ACM-Team Tic Tac Toe

    我的代码: #include <bits/stdc++.h> using namespace std; int main() { char a[3][3]; int i,j=0; for( ...

  9. LeetCode 5275. 找出井字棋的获胜者 Find Winner on a Tic Tac Toe Game

    地址 https://www.acwing.com/solution/LeetCode/content/6670/ 题目描述A 和 B 在一个 3 x 3 的网格上玩井字棋. 井字棋游戏的规则如下: ...

随机推荐

  1. secureCRT恶意终止下次无法启动

    secureCRT使用中恶意中断后会在C:\Documents and Settings\wuyipeng\Application Data目录下产生一个secureCRT.dmp文件 下次正常运行s ...

  2. google chrome 浏览器书签丢失问题

    在一次新打开标签页时,电脑卡死,强制重启后打开google chrome 浏览器,发现历史什么的都在,但书签栏全部丢失了 找到 系统盘:\Users\用户名\AppData\Local\Google\ ...

  3. qml: 软件启用前插入广告;

    一般来说,免费软件或者部分商业软件在发布前都会放一些广告在软件上. 下面是我自己的方案(哪位有更好的方案,请告知,先谢): ...... ApplicationWindow{ visible: !ad ...

  4. es6基础知识总结(附加)

    附加: 字符串扩展: 1. includes(str) : 判断是否包含指定的字符串2. startsWith(str) : 判断是否以指定字符串开头3. endsWith(str) : 判断是否以指 ...

  5. 信用评分卡 (part 4 of 7)

    python信用评分卡(附代码,博主录制) https://study.163.com/course/introduction.htm?courseId=1005214003&utm_camp ...

  6. DotNet 资源大全中文版

    https://blog.csdn.net/fhzh520/article/details/52637545 目录 算法与数据结构(Algorithms and Data structures) 应用 ...

  7. Ubuntu 开启SSH服务以及有关设置:安装,指定端口号、免密登录、远程拷贝

    本文所用系统为 Ubuntu 18.04   什么是SSH?     简单说,SSH是一种网络协议,用于计算机之间的加密登录.全名为:安全外壳协议.为Secure Shell的缩写.SSH为建立在应用 ...

  8. Uncaught DOMException: Failed to construct 'WebSocket': The URL '/qibao/websocket/service1000' is invalid.

    出现这个问题是构造 WebSocket失败了. js代码改成 //实现化WebSocket对象,指定要连接的服务器地址与端口 建立连接//等同于socket = new WebSocket(path+ ...

  9. LeetCode(194.Transpose File)(awk进阶)

    194. Transpose File Given a text file file.txt, transpose its content. You may assume that each row ...

  10. Golang入门教程(十五)指针

    什么是指针? 指针是一个变量,用于存储另一个变量的内存地址. 在上面的例子中,变量b的值是156,存储在内存地址0x1040a124. 变量a包含b的地址. 可以说现在a指向b. 声明指针 指向类型  ...