L - Tic-Tac-Toe FZU - 2283 (思维)
题目链接:
L - Tic-Tac-Toe
题目大意:两个人下棋,一共是三步棋,第一个人下一步,第二个人下一步,第三个人下一步,然后问你在两个人在都足够聪明的条件下,第一个人能否获胜?(获胜的前提,其中一个人的三个棋子连成了一条线)。
参考博客:
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 (思维)的更多相关文章
- 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 ...
- 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 ...
- [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( ...
- LeetCode 5275. 找出井字棋的获胜者 Find Winner on a Tic Tac Toe Game
地址 https://www.acwing.com/solution/LeetCode/content/6670/ 题目描述A 和 B 在一个 3 x 3 的网格上玩井字棋. 井字棋游戏的规则如下: ...
随机推荐
- 拓展Unity3D编辑器
/*** * * 编辑器创建新窗口,并设置窗口布局 * * * * * */ using System.Collections; using System.Collections.Generic; u ...
- 过滤富文本编辑器中的html元素和其他元素
https://blog.csdn.net/fjssharpsword/article/details/53467079 1.应用场景:从一份html文件中或从String(是html内容)中提取纯文 ...
- Luogu P2617 Dynamic Rankings
带修主席树的模板,因为状态不好所以敲了很长时间,不过写完感觉能更好地理解主席树了. 核心其实就是树状数组套主席树,维护方法不再是以前的那种一步一修改,而是对于树状数组上的每一个点建立一棵权值线段树,然 ...
- (count 或直接枚举) 统计字符 hdu1860
统计字符(很水) 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1860 Time Limit: 1000/1000 MS (Java/Others) ...
- Shiro进行简单的身份验证(二)
一个Realm数据源: shiro.ini: [users] wp=123456 main方法执行认证: package com.wp.shiro; import org.apache.shiro.S ...
- Xshell使用笔记
Xshell 使用笔记 1second即1s1millisecond即1ms1s=1000ms Xshell中输入冒号 : 表示终止当前命令的意思 SSH 是Secure Shell ,安全外壳协议的 ...
- Vue less使用scope时渗入修改子组件样式
@deep: ~'>>>'; .wrap { @{deep} .component1 { width: 120px; } }
- Hbase_02、Hbase的常用的shell命令&Hbase的DDL操作&Hbase的DML操作(转)
阅读目录 前言 一.hbase的shell操作 1.1启动hbase shell 1.2执行hbase shell的帮助文档 1.3退出hbase shell 1.4使用status命令查看hbase ...
- JAVA-比较浮点型数据
Float public static void main(String[] args) { Float x = 12.4F; Float y = 12.4F; // 比较对象地址 System.ou ...
- MVC项目报错 ”基础提供程序在 Open 上失败”
问题: 今天将一个.net mvc项目拷贝到另一台电脑上,重新部署的时候,出现以下异常信息: “System.Data.Entity.Core.EntityCommandExecutionExcept ...