[USACO] Team Tic Tac Toe

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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值