题目

  • Problem Description
    Farmer John owns 26 cows, which by happenstance all have names starting with different letters of the alphabet, so Farmer John typically refers to each cow using her first initial – a character in the range A…Z.

    The cows have recently become fascinated by the game of tic-tac-toe, but since they don’t like the fact that only two cows can play at a time, they have invented a variant where multiple cows can play at once! Just like with regular tic-tac-toe, the game is played on a 3×3 board, only instead of just Xs and Os, each square is marked with a single character in the range A…Z to indicate the initial of the cow who claims that square.

    An example of a gameboard might be:
                COW
                XXO
                ABC

    The cows fill in each of the nine squares before they become confused about how to figure out who has won the game. Clearly, just like with regular tic-tac-toe, if any single cow has claimed an entire row, column, or diagonal, that cow could claim victory by herself. However, since the cows think this might not be likely given the larger number of players, they decide to allow cows to form teams of two, where a team of two cows can claim victory if any row, column, or diagonal consists only of characters belonging to the two cows on the team, and moreover if characters from both cows (not just one) are used in this row, column, or diagonal.

    Please help the cows figure out how many individuals or two-cow teams can claim victory. Note that the same square on the game board might possibly be usable in several different claims to victory.

  • Input
    The input consists of three lines, each of which is three characters in the range A…Z.

  • Output
    Output should consist of two lines. On the first line, output the number of individual cows who can claim victory. On the second line, output the number of two-cow teams that could claim victory.

  • input
    COW
    XXO
    ABC

  • output
    0
    2

题意

井字棋乱斗,不同的牛下的棋子用不同的字母表示.
获胜条件:
三个相同的字母连成了三个(行,列,对角线),则视为个人获胜。两个不同种的字母连成了三个,则视为组队获胜.

分别求出获胜的个人和队伍数.

思路

列举遍历所有情况。。
需要把已经获胜的人或队伍标记起来,防止重复计算.

代码

#include <bits/stdc++.h>
using namespace std;
int main() {char m[6][6];scanf("%s",&m[1][1]);scanf("%s",&m[2][1]);scanf("%s",&m[3][1]);int win_one=0;int vis[256]= {0};int win_two=0;int vis2[66000]= {0};
//个人队伍for(int i=1; i<=3; ++i)if(m[i][1]==m[i][2] and m[i][2]==m[i][3])if(vis[m[i][1]]==0)win_one++,vis[m[i][1]]=m[i][1];for(int i=1; i<=3; ++i)if(m[1][i]==m[2][i] and m[2][i]==m[3][i])if(vis[m[1][i]]==0)win_one++,vis[m[1][i]]=m[1][i];if(m[1][1]==m[2][2] and m[2][2]==m[3][3])if(vis[m[1][1]]==0)win_one++,vis[m[1][1]]=m[1][1];if(m[1][3]==m[2][2] and m[2][2]==m[3][1])if(vis[m[1][3]]==0)win_one++,vis[m[1][3]]=m[1][3];
//组队获胜int t;for(int i=1; i<=3; ++i) {if(m[i][1]==m[i][2] and m[i][1]!=m[i][3]) {t=m[i][1]*m[i][3];if(vis2[ t ] == 0)win_two++,vis2[ t ] = t;}if(m[i][2]==m[i][3] and m[i][1]!=m[i][2]) {t=m[i][1]*m[i][2];if(vis2[ t ] == 0)win_two++,vis2[ t ] = t;}if(m[i][1]==m[i][3] and m[i][1]!=m[i][2]) {t=m[i][1]*m[i][2];if(vis2[ t ] == 0)win_two++,vis2[ t ] = t;}}for(int i=1; i<=3; ++i) {if(m[1][i]==m[2][i] and m[1][i]!=m[3][i]) {t=m[1][i]*m[3][i];if(vis2[ t ] == 0)win_two++,vis2[ t ] = t;}if(m[2][i]==m[3][i]and m[1][i]!=m[2][i]) {t=m[1][i]*m[2][i];if(vis2[ t ] == 0)win_two++,vis2[ t ] = t;}if(m[1][i]==m[3][i]and m[1][i]!=m[2][i]) {t=m[1][i]*m[2][i];if(vis2[ t ] == 0)win_two++,vis2[ t ] = t;}}if( m[1][1] == m[2][2] and m[1][1]!=m[3][3]) {t=m[1][1]*m[3][3];if(vis2[t]==0)win_two++,vis2[t]=t;}if( m[1][1] == m[3][3] and m[1][1]!=m[2][2]) {t=m[1][1]*m[2][2];if(vis2[t]==0)win_two++,vis2[t]=t;}if( m[2][2] == m[3][3] and m[1][1]!=m[3][3]) {t=m[1][1]*m[3][3];if(vis2[t]==0)win_two++,vis2[t]=t;}if( m[1][3] == m[2][2] and m[1][3]!=m[3][1]) {t=m[1][3]*m[3][1];if(vis2[t]==0)win_two++,vis2[t]=t;}if( m[3][1] == m[2][2] and m[3][1]!=m[1][3]) {t=m[3][1]*m[1][3];if(vis2[t]==0)win_two++,vis2[t]=t;}if( m[1][3] == m[3][1] and m[2][2]!=m[3][1]) {t=m[2][2]*m[3][1];if(vis2[t]==0)win_two++,vis2[t]=t;}cout << win_one<<endl<<win_two<<endl;return 0;
}

Team Tic Tac Toe相关推荐

  1. python二维游戏示例_Python实现的井字棋(Tic Tac Toe)游戏示例

    本文实例讲述了Python实现的井字棋(Tic Tac Toe)游戏.分享给大家供大家参考,具体如下: 说明 用python实现了井字棋,整个框架是本人自己构思的,自认为比较满意.另外,90%+的代码 ...

  2. python游戏代码运行不了_无法使我的tic tac toe游戏在python中正确运行

    转不到"玩家1"的原因是你的支票中缺少一个空格.你也没有正确地检查一个玩家何时获胜,这就是为什么你会有这种奇怪的行为.你需要检查每个位置,而不仅仅是最后一个.我还添加了对用户输入的 ...

  3. react中使用构建缓存_通过在React中构建Tic Tac Toe来学习ReasonML

    react中使用构建缓存 3. 7. 2018: UPDATED to ReasonReact v0.4.2 3. 7. 2018:更新为ReasonReact v0.4.2 You may have ...

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

  5. amazon.设计1. tic tac toe

    //不觉中 已经全力找工作好久好久了.大概有1年半了.身心疲惫,不要放弃.曙光快来了. 1.tic tac toe //http://www.ntu.edu.sg/home/ehchua/progra ...

  6. python井字棋ai,python 井字棋(Tic Tac Toe)

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

  7. python井字棋游戏代码_Python实现的井字棋(Tic Tac Toe)游戏示例

    Python实现的井字棋(Tic Tac Toe)游戏示例 来源:中文源码网    浏览: 次    日期:2018年9月2日 [下载文档:  Python实现的井字棋(Tic Tac Toe)游戏示 ...

  8. C++ 很有趣:编写一个井字游戏 (Tic Tac Toe)

    英文原文:C++ is fun: Writing a Tic Tac Toe Game 这个有趣的C++系列打算展示一下使用C++写代码可以和其他主流语言一样高效而有趣.在第二部分,我将向你展示使用C ...

  9. 圈叉游戏 java_【炫光圈叉棋】炫光圈叉棋 Tic Tac Toe Glow 1.8.1下载_安卓(android)软件下载-魅族溜...

    一款炫光风格的圈叉棋游戏,支持单/双人模式.圈叉棋,英文:tic-tac-toe,别名:圈叉游戏.是一种游戏,3*3的9个方格子,先下者画圈,后下者画叉,每人可以在任意没有对方棋子的封闭方格里下一次, ...

  10. java tic tac toe_请问我这个tic tac toe的游戏代码的问题在哪里

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 Scanner in = new Scanner(System.in); final int SIZE =3; int[][] board = new i ...

最新文章

  1. FFmpeg中libavutil库简介及测试代码
  2. python09-魔法方法
  3. 卷积神经网络(卷积层,激活函数Relu,池化层,计算公式及API解释)
  4. windows功能_你的Windows杀毒软件有这个功能吗?
  5. 【今日CV 计算机视觉论文速览 第97期】Tue, 9 Apr 2019
  6. 联发科发布天玑5G开放架构 采用该定制芯片终端7月上市
  7. 压测工具下载地址说明及汇总
  8. Shell的脚本编程
  9. 转载:人生真相之为何你应该假装自己是一个电脑白痴(原文pconline)
  10. 手把手教你安装IAR
  11. navicat中文破解版,navicat for mysql10.0.11简体中文破解版
  12. div两侧的boder断开 消失 奇怪
  13. 基于thinkphp开源cms 对比
  14. 多项式展开的逆过程的MATLAB实现
  15. 利用ECharts实现数据的左右移动
  16. How to learn a new technology
  17. Unity3D打印拓展XMDebug
  18. 深入计算机组成原理(十二)理解电路:从电报机到门电路,我们如何做到“千里传信”?
  19. javascript控制台_JavaScript控制台简介
  20. activiti使用详解

热门文章

  1. html css 分页样式,css中分页样式
  2. jpg转换成pdf转换器免费版
  3. OC_AddressBook_通讯录
  4. jde多目标_CVPR 2020 多目标跟踪算法JDE 训练
  5. HTML实现简单的贪吃蛇小游戏(附完整源码)
  6. 编写Dockerfile来构建nginx:latest镜像
  7. 百度统计之百度代码引用
  8. HTML炫彩按钮,PS打造炫彩的开始图标按钮
  9. Android 布局优化方案
  10. 志金庸小说里,让你印象最深的是哪一段?