Team Tic Tac Toe [codeforces] (码农题)_御堂和果子的博客-程序员ITS301

技术标签: 码农  

原题传送门


题面:

Team Tic Tac Toe

                              time limit per test : 1 second
                           memory limit per test : 256 megabytes
                                  input : standard input
                                  output : standard output

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.

Sample Input

COW
XXO
ABC

Sample Output

0
2

题面描述

变形的井字棋,下棋的牛有26个,不限制数量(0~9),每个牛的棋子对应一个大写字母.求出单头牛能胜利和两头牛联合起来能够获胜的数量.

题目分析

码农题目.只要把符合胜利情况的状态写出来去查就可以了,代码量有点大而已.但还是要注意一下,第一个输出是单头牛的胜利数量,而第二个输出是两头牛联合起来的胜利数量(是两头牛联合,两头牛!!!)

具体代码

#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
bool chr[30];
char arr[4][4];
bool check(int i, int j)
{
    int flag1 , flag2;
    for(int x = 1; x <= 3; x++)
    {
        flag1 = 0 , flag2 = 0;
        for(int y = 1; y <= 3; y++)
        {
            if(arr[x][y] == i+'A'-1)
            {
                flag1++;
            }
            else if(arr[x][y] == j+'A'-1)
            {
                flag2++;
            }
        }
        if(flag1 == 3 && j == 0)
        {
            return true;
        }
        else if(flag1+flag2 == 3 && flag1 != 3 && flag2 != 3)
        {
            return true;
        }
    }

    for(int x = 1; x <= 3; x++)
    {
        flag1 = 0 , flag2 = 0;
        for(int y = 1; y <= 3; y++)
        {
            if(arr[y][x] == i+'A'-1)
            {
                flag1++;
            }
            else if(arr[y][x] == j+'A'-1)
            {
                flag2++;
            }
        }
        if(flag1 == 3 && j == 0)
        {
            return true;
        }
        else if(flag1+flag2 == 3 && flag1 != 3 && flag2 != 3)
        {
            return true;
        }
    }

    flag1 = 0 , flag2 = 0;

    if(arr[2][2] == i+'A'-1) flag1++;
    if(arr[2][2] == j+'A'-1) flag2++;
    if(j == 0 && flag1 == 0) return false;
    if(j == 0)
    {
        if(arr[1][1] == i+'A'-1 && arr[3][3] == i+'A'-1)
        {
            return true;
        }
        if(arr[1][3] == i+'A'-1 && arr[3][1] == i+'A'-1)
        {
            return true;
        }
    }
    else
    {
        if(arr[1][1] == i+'A'-1) flag1++;
        if(arr[1][1] == j+'A'-1) flag2++;
        if(arr[3][3] == i+'A'-1) flag1++;
        if(arr[3][3] == j+'A'-1) flag2++;
        if(flag1+flag2 == 3 && flag1 != 3 && flag2 != 3)
        {
            return true;
        }
        if(arr[1][3] == i+'A'+1) flag1++;
        if(arr[1][3] == j+'A'+1) flag2++;
        if(arr[3][1] == i+'A'+1) flag1++;
        if(arr[3][1] == j+'A'+1) flag2++;
        if(flag1+flag2 == 3 && flag1 != 3 && flag2 != 3)
        {
            return true;
        }
    }
    return false;
}

int main()
{
    for(int i = 1; i <= 3; i++)
    {
        for(int j = 1; j <= 3; j++)
        {
            cin >> arr[i][j];
            chr[arr[i][j]-'A'+1] = true;
        }
    }
    int cnt_alone = 0;
    for(int i = 1; i <= 26; i++)
    {
        if(chr[i] && check(i , 0))
        {
            cnt_alone++;
        }
    }
    int cnt_two = 0;
    for(int i = 1; i <= 26; i++)
    {
        for(int j = i+1; j <= 26; j++)
        {
            if(chr[j] && chr[i] && check(i , j))
            {
                cnt_two++;
            }
        }
    }
    cout << cnt_alone << endl;
    cout << cnt_two << endl;
    return 0;
}
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_43726593/article/details/88376154

智能推荐

matlab corr2原码,Ncorr-二维数字图像校正软件_liujuan63795的博客-程序员ITS301

Ncorr - 2D Digital Image Correlation SoftwareNcorr is an open source 2D digital image correlation MATLAB program. It has an accessible and intuitive GUI, uses many novel 2D DIC algorithms, is wholly c...

KEIL C51编译出现了ADDRESS SPACE OBERFLOW_天冰天降的博客-程序员ITS301_oberflow

好长时间不使用c51了,今天使了一下,除了ADDRESS SPACE OBERFLOW错误,上网一查,原来是data区溢出了,产生这个问题的原因是变量定义,volatile unsigned char idata inbuf1[INBUF_LEN],outbuf[OUTBUF_LEN]; 当然了,核心还是89c52的data区太小了,data+idata一共就是256byte,所以当变

Ubuntu install python3.7后pip install 出现没有ssl问题_37号楼梯的博客-程序员ITS301_pip ssl ubuntu

1.安装sslsudo apt-get install opensslsudo apt-get install libssl-dev2. 修改Moudles/Setup (该目录在python的解压目录下)vim Modules/Setup#修改结果如下:# Socket module helper for socket(2)_socket socketmodule.c timemodule.c# Socket module helper for SSL support; you m

Django笔记_我是黎族人的博客-程序员ITS301

model到目前为止,当我们的程序涉及到数据库相关操作时,我们一般都会这么搞:创建数据库,设计表结构和字段使用 MySQLdb 来连接数据库,并编写数据访问层代码业务逻辑层去调用数据访问层执行数据库操作import MySQLdb def GetList(sql): db = MySQLdb.connect(user='root', db='wupeiqidb', pas...

python字典类型实现的键值对的映射_python数据类型-映射和集合-字典_weixin_39774491的博客-程序员ITS301

字典是python语言中唯一的映射类型,映射对象里哈希值(键,key)和指向的对象(值,value)是一对多的关系。一个字典对象是可变的,是一个容器类型,可存储任意个数的python对象,其中也可以包括其他容器类型。1.创建字典和给字典赋值创建字典只需要把字段赋值给一个变量,不管这个字典是否包含元素。1 >>> dict1 ={}2 >>> dict2 = {'name':'earth', 'po...

springboot+cas5.x+shiro+pac4j实现sso集成自定义数据库认证(二)_四道街硬汉的博客-程序员ITS301

现在咱们开发环境搭好了就一切好办了只需要增加两个类,修改两个配置文件就ok了第一个类,登录验证类类里面用到了com.mysql.jdbc.Driver,所以你们懂得,记得在pom里面加入对mysql驱动的依赖,上一篇里提到过了package com.hugeo.cas;import org.apereo.cas.authentication.HandlerResult;...

随便推点

RK3568平台开发系列讲解(驱动篇)kthread_worker:怎么把内核线程当工人?_内核笔记的博客-程序员ITS301_ahd rk3568

kthread_worker:怎么把内核线程当工人?驱动传输数据低速数据:驱动同步传输简单直接、传输效率低高速数据:驱动交给内核来异步传输机制复杂、无阻塞kthread_worker结构体include/linux/kthread.h表示把内核线程抽象为流水线工人,按序处理其他线程/进程交付的批量工作struct kthread_worker { unsigned int flags; spinlock_t lock; struct list_head wor

使用jquery报错replace is not a function_1440!的博客-程序员ITS301_replace不是function

问题描述:Jquery在使用replace() 的报错:提示“replace is not a function”代码参考如下:var d=15243;var c=d.replace('3','15');上诉异常原因:replace的数据应该为string类型针对“replace is not a function”网上给出了好几个解释:js文件引用顺序,调整js顺序js文件重...

Unity灯光渲染之SkyBox_Cco丶的博客-程序员ITS301_unity shadergraph skybox

天空盒的制作:我们先找一张高清的图,导入unity,选中把类型设置为Cube,新建一个材质球,shader选择然后将我们的天空和图片素材拖进来,这样一个天空盒就制作成功了TintColor:可以通过改变该颜色,来改变天空盒整体色调。Exposure:曝光度,正常为1,越大越来越亮。Rotation: 旋转天空盒将我们制作好的天空盒拖给天空,或者在lighti...

ubuntu20.04下编译rovio代码报“undefined reference to ‘__glew***‘“_完颜小白的博客-程序员ITS301_libgcc.so

环境: ubuntu20.04, ROS Noetic;rovio源码,执行catkin_make报如下错误:[ 75%] Building CXX object rovio/CMakeFiles/feature_tracker_node.dir/src/feature_tracker_node.cpp.o[ 80%] Building CXX object rovio/CMakeFiles/rovio_node.dir/src/rovio_node.cpp.o[ 85%] Buil

jenkins把pipeline从源码剥离,单独git仓库管理_weixin_36013896的博客-程序员ITS301_jenkinsfile与代码分离

Jenkins-Pipeline实践浅谈 - 知乎Pipeline 实践:将 Jenkinsfile 与项目分离 - 简书Jenkinsfile之伤在Pipeline中至关重要的就是Jenkinsfile,类似Dockerfile,包含了Job所有需要执行的步骤,根据Pipeline的使用规则,我们常常需要把Jenkinsfile文件放到对应工程代码的根目录,Jenkins在获取工程代码后会解析Jenkinsfile,然后根据代码顺序执行下去,达到持续集成的效果。但是这种模式有一个致命的

Linux使用命令行下查看Sqlite3数据库_linux查看sqlite3_InterestingFigure的博客-程序员ITS301

Linux使用命令行下查看Sqlite3数据库安装sqlite3使用安装sqlite3sudo apt-get install sqlite3等到跳出Do you want to continue? [Y/n] 的时候,输入Y回车即可使用进入.db目录sqlite3 xx.db.mode column.headers onselect * from user;...

推荐文章

热门文章

相关标签