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.

Example

input

COW
XXO
ABC

output

0
2

Note

In this example, no single cow can claim victory. However, if cows C and X team up, they can win via the C-X-C diagonal. Also, if cows X and O team up, they can win via the middle row.

解析

一字棋规则,输出第一行是某个字母能赢的个数,第二行是某两个字母组队能赢的个数。

要注意的是,组队的时候是两个自身单独不能赢的组队。即组成的队胜利的时候三个字母不能相同。

(我一直WA这个...)

代码(有点丑但是思路蛮清晰)

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
char a[4][4];
int b[100][3],mark[100];
int m=0,n=0;
int cnt=0,cnt2=0;
int dif(char a,char b,char c,int r,int t)//判断胜利与否
{if(a!=b&&b!=c&&a!=c)//三个字母都不相同(即两种胜利都不满足)return 0;if((a!=r&&a!=t)||(b!=r&&b!=t)||(c!=r&&c!=t))//出现非组队字母return 0;if(r==t)cnt++;    //三个字母相同满足单独胜利if((a!=b||b!=c||a!=c)&&r!=t)cnt2++;    //满足组队胜利
}
int main()
{int i,j,r,t,k;for(i=1;i<=3;i++){for(j=1;j<=3;j++)a[i][j]=getchar(),mark[a[i][j]]=1;getchar();}for(r='A';r<='Z';r++){for(t=r;t<='Z';t++)//t=r保证不会出现重复{cnt=0,cnt2=0;if(mark[r]==0||mark[t]==0)continue;for(i=1;i<=3;i++)    //行dif(a[i][1],a[i][2],a[i][3],r,t);for(j=1;j<=3;j++)    //列dif(a[1][j],a[2][j],a[3][j],r,t);//对角线dif(a[1][1],a[2][2],a[3][3],r,t);dif(a[1][3],a[2][2],a[3][1],r,t);//字母r的两种胜利情况if(cnt) b[r][1]++;if(cnt2)b[r][2]++;}}for(k=60;k<100;k++) //65-90即A-Z{if(b[k][1])m++;if(b[k][2])n+=b[k][2];}printf("%d\n%d\n",m,n);return 0;
}

[USACO] 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. 多元化和专一化的关系
  2. JEECG v3视频陆续更新
  3. 转载:ImportError: No module named ‘httplib‘
  4. 限时抢购促销海报设计没想法,看这里!眼见的倒计时紧迫感
  5. android 动画坐标,Android 动画之TranslateAnimation应用详解
  6. 漫画 | Linux 并发和竞态问题究竟是什么?
  7. ROS的学习(五)在工作空间中构建和使用catkin包
  8. character-RNN模型介绍以及代码解析
  9. 在Spinnaker中创建微服务部署管道
  10. python工具箱_python 工具箱
  11. MACD神器 通达信指标公式 副图 源码 无加密 无未来
  12. 微信小程序路线规划导航,选择起点和终点路线规划
  13. 2018最佳GAN论文回顾
  14. 技校自我鉴定范文计算机600字,技校自我鉴定100字范文18篇
  15. 怎样做风险评估?风险评估有哪些具体实施流程?
  16. 大据数技术之高频面试题8.0.9
  17. 如何在Tableau Desktop中创建自定义调色板 - 优阅达
  18. 【WebView】关于Android WebView 的一些坑
  19. Ubuntu20.04 配置网卡信息
  20. SLAM大牛Cyrill 开源SuMa ++:基于语义激光雷达过滤动态物体提高定位精度

热门文章

  1. 《从0开始学大数据》的启示
  2. 从0开始学大数据(十四)
  3. java数字货币转化_将数字货币金额转换为大写格式
  4. 35岁以后你还能干嘛?
  5. 23种设计模式用英语如何表达?
  6. python字符串格式化是什么意思_python字符串格式化什么意思
  7. c语言贪吃蛇游戏问题描述,贪吃蛇小游戏的几个问题
  8. [渝粤教育] 天津师范大学 教育心理学(唐卫海) 参考 资料
  9. Android带动画进度条简单实现
  10. MySQL单表数据量大优化方案及注意事项