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 的网格上玩井字棋. 井字棋游戏的规则如下: ...
随机推荐
- Linux:不同文件相同列字符合并文件(awk函数)
存在file1.txt,其内容如下: H aa 0 0 1 -9 H bb 0 0 2 -9 H cc 0 0 2 -9 存在file2.txt,其内容如下: H aa 0 0 0 -9 asd qw ...
- jQuery中mouseleave和mouseout的区别详解
很多人在使用jQuery实现鼠标悬停效果时,一般都会用到mouseover和mouseout这对事件.而在实现过程中,可能会出现一些不理想的状况. 先看下使用mouseout的效果: <p> ...
- Luogu P3521 [POI2011]ROT-Tree Rotations
题目链接 \(Click\) \(Here\) 线段树合并,没想到学起来意外的很简单,一般合并权值线段树. 建树方法和主席树一致,即动态开点.合并方法类似于\(FHQ\)的合并,就是把两棵树的信息整合 ...
- 关键字(5):cursor游标:(循环操作批量数据)
declare cursor stus_cur is select * from students; --定义游标并且赋值(is 不能和cursor分开使用) cur_stu studen ...
- CodeChef - BLACKCOM 可行性dp转最优化树dp
https://www.codechef.com/problems/BLACKCOM 题意:一颗5000个黑白结点的树,10W个查询寻找是否存在大小s并且有t和黑节点的子图 一开始就觉得应当是一个树d ...
- bzoj1003 最短路+dp
遇到小范围数据的题目就容易被限制了思维,我单知道数据小可以跑很多遍最短路,但我没想到暴力跑N ^ 2的最短路也能过 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输 ...
- img标签的onerror事件
#情景分析: 有时,img标签中的src图片加载失败,原来的图片位置会出现一个碎片图标,这样让人很不爽,如何变得美观些呢? #解决方案: 可以借用img标签的onerror事件,img标签支持oner ...
- JAVA核心技术I---JAVA基础知识(文件系统及java文件基本操作)
一:文件概述 文件系统是由OS(操作系统)管理的 文件系统和Java进程是平行的,是两套系统 文件系统是由文件夹和文件递归组合而成 文件目录分隔符 –Linux/Unix 用/隔开 –Windows用 ...
- @JsonFormat的导包问题
@DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss")//注解可以以该格式注入格式@JsonFormat(locale="zh& ...
- Problems found loading plugins: Plugin "GlassFish Integration" was not loaded: required plugin "Java EE: EJB, JPA, Servlets" is disabled.
idea启动报错:并且无法部署web项目 Problems found loading plugins: Plugin "GlassFish Integration" was no ...