POJ The Game

news2025/2/10 22:11:19

原题目:传送锚点

1.题目

                                                                The Game

Description

A game of Renju is played on a 19*19 board by two players. One player uses black stones and the other uses white stones. The game begins in an empty board and two players alternate in placing black stones and white stones. Black always goes first. There are 19 horizontal lines and 19 vertical lines in the board and the stones are placed on the intersections of the lines.

Horizontal lines are marked 1, 2, ..., 19 from up to down and vertical lines are marked 1, 2, ..., 19 from left to right.


The objective of this game is to put five stones of the same color consecutively along a horizontal, vertical, or diagonal line. So, black wins in the above figure. But, a player does not win the game if more than five stones of the same color were put consecutively.

Given a configuration of the game, write a program to determine whether white has won or black has won or nobody has won yet. There will be no input data where the black and the white both win at the same time. Also there will be no input data where the white or the black wins in more than one place.

Input

The first line of the input contains a single integer t (1 <= t <= 11), the number of test cases, followed by the input data for each test case. Each test case consists of 19 lines, each having 19 numbers. A black stone is denoted by 1, a white stone is denoted by 2, and 0 denotes no stone.

Output

There should be one or two line(s) per test case. In the first line of the test case output, you should print 1 if black wins, 2 if white wins, and 0 if nobody wins yet. If black or white won, print in the second line the horizontal line number and the vertical line number of the left-most stone among the five consecutive stones. (Select the upper-most stone if the five consecutive stones are located vertically.)

Sample Input

1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 2 0 0 2 2 2 1 0 0 0 0 0 0 0 0 0 0
0 0 1 2 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 2 2 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 2 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Sample Output

1
3 2

2.中文翻译

                                                                        游戏

描述

两个玩家在一块19*19的木板上玩一场连珠游戏。一个玩家使用黑色石头,另一个使用白色石头。游戏在一块空木板上开始,两名玩家交替放置黑色石头和白色石头。黑色总是排在第一位。木板上有19条水平线和19条垂直线,石头放在这些线的交点上。

给定游戏的配置,编写一个程序来确定是白赢了,还是黑赢了,或者还没有人赢。不会有黑和白同时获胜的输入数据。此外,也不会有白或黑在多个地方获胜的输入数据。

输入

 输入的第一行包含一个整数t(1<=t<=11),即测试用例的数量,后面是每个测试用例的输入数据。每个测试用例由19行组成,每行有19个数字。黑色石头用1表示,白色石头用2表示,0表示没有石头。

输出

每个测试用例应该有一到两行。在测试用例输出的第一行中,如果黑获胜,则应该打印1,如果白获胜,则打印2,如果还没有人获胜,则应打印0。如果黑或白获胜,则在第二行打印连续五块石头中最左边石头的水平线编号和垂直线编号。(如果五块连续的石头垂直放置,则选择最上面的石头。)

样例输入

1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 2 0 0 2 2 2 1 0 0 0 0 0 0 0 0 0 0
0 0 1 2 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 2 2 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 2 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

 样例输出

1
3 2

3.代码实现(思路看注释足矣)

#encoding=utf-8
def check_winner(board):
    # 检查横向
    for i in range(19):
        for j in range(15):
            if board[i][j] == board[i][j + 1] == board[i][j + 2] == board[i][j + 3] == board[i][j + 4] and board[i][
                j] != 0:
                return (board[i][j], i + 1, j + 1)

    # 检查竖向
    for i in range(15):
        for j in range(19):
            if board[i][j] == board[i + 1][j] == board[i + 2][j] == board[i + 3][j] == board[i + 4][j] and board[i][
                j] != 0:
                return (board[i][j], i + 1, j + 1)

    # 检查左上到右下的斜线
    for i in range(15):
        for j in range(15):
            if board[i][j] == board[i + 1][j + 1] == board[i + 2][j + 2] == board[i + 3][j + 3] == board[i + 4][
                j + 4] and board[i][j] != 0:
                return (board[i][j], i + 1, j + 1)

    # 检查左下到右上的斜线
    for i in range(4, 19):
        for j in range(15):
            if board[i][j] == board[i - 1][j + 1] == board[i - 2][j + 2] == board[i - 3][j + 3] == board[i - 4][
                j + 4] and board[i][j] != 0:
                return (board[i][j], i + 1, j + 1)

    # 如果没有获胜者
    return (0, 0, 0)


t = int(input())
for _ in range(t):
    board = [list(map(int, input().split())) for _ in range(19)]
    winner, row, col = check_winner(board)
    print(winner)
    if winner != 0:
        print(row, col)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/640334.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

面对工作中的失误:从错误中学习与成长

&#x1f604;作者简介&#xff1a; 小曾同学.com,一个致力于测试开发的博主⛽️&#xff0c;主要职责&#xff1a;测试开发、CI/CD 如果文章知识点有错误的地方&#xff0c;还请大家指正&#xff0c;让我们一起学习&#xff0c;一起进步。&#x1f60a; 座右铭&#xff1a;不想…

C99的一些新特性记录

固长类型头文件<stdint.h> 由于历史原因&#xff0c;C语言中实现的整型数只保证了在不同硬件体系中的最小长度&#xff0c;因此在使用时&#xff0c;需要根据代码实际运行的平台来确定类型的长度&#xff0c;这导致代码非常不方便移植。C99标准通过增加固长类型头文件引入…

【Unity3D】屏幕深度和法线纹理简介

1 前言 1&#xff09;深度纹理和法线纹理的含义 深度纹理本质是一张图片&#xff0c;图片中每个像素反应了屏幕中该像素位置对应的顶点 z 值相反数&#xff08;观察坐标系&#xff09;&#xff0c;之所以用 “反应了” 而不是 “等于”&#xff08;或 “对应” &#xff09;&am…

chatgpt赋能python:Python浮点型转换为整型的方法和应用场景

Python浮点型转换为整型的方法和应用场景 介绍 Python的浮点型和整型在数值计算中应用广泛。有时候我们需要将一个浮点数转换为整数&#xff0c;这时候就需要使用Python提供的一些函数来完成转换。本文将介绍Python浮点型转换为整型的方法和应用场景。 浮点型和整型的区别 …

初探MyBatis实现简单查询

一、创建数据库与表 1、创建数据库 在Navicat里创建MySQL数据库 - testdb&#xff0c;采用utf8mb4字符集 2、创建用户表 CREATE TABLE t_user (id int(11) NOT NULL AUTO_INCREMENT,name varchar(50) DEFAULT NULL,age int(11) DEFAULT NULL,address varchar(255) DEFAULT…

SpringBoot的日志文件

文章目录 前言日志怎么用自定义打印日志⽇志级别 - 了解⽇志持久化Lombok提供的方法 前言 上文讲述了 SpringBoot项目的构建 与配置文件的使用 ,下面来介绍 SpringBoot 的日志文件 , 日志在程序 中起到的作用是很大的 , 谁写的程序能不报错误呢, 日志就是一种让你快速找到错误…

Linux环境变量配合权限维持手法

前言&#xff1a; 权限维持的时候有其中有两种&#xff0c;一种是alias别名、第二种是prompt_command&#xff0c;这里我们可以将其添加到环境变量中&#xff0c;每次运行的时候都可以使用&#xff0c;从而达到权限控制的效果&#xff0c;而不是临时执行的效果。 环境变量&am…

harbor仓库的搭建

harbor仓库的搭建 前言一、准备二、registry私有仓库拉取registry镜像上传镜像下载镜像添加私有仓库解析配置使用非加密端口拉取镜像 三、仓库加密域名保持一致部署客户端证书&#xff0c;不然会报错验证仓库认证删除registry&#xff0c;重建登录仓库&#xff0c;不然无法上传…

[论文阅读笔记76]GPT Understands, Too(P-tuning)

1. 基本信息 题目论文作者与单位来源年份GPT Understands, Too清华大学 Citations, References 论文链接&#xff1a;https://arxiv.org/pdf/2103.10385.pdf 论文代码&#xff1a; 2. 要点 研究主题问题背景核心方法流程亮点数据集结论论文类型关键字微调大模型采用传统微…

css空间转换

目录 1. 3D移动 translate3d 1.1 三维坐标系 1.2 3D移动 translate3d 1.3 透视 perspective 1.4 translateZ 2. 3D旋转 rotate3d 2.1 左手法则-判断元素旋转方向的取值正负 3. 3D呈现 transform-style【***】 4. 3D缩放 transform:scale3d 1. 3D移动 translate3d …

nacos运行报错-jar: file does not existCan‘t retrieve image ID from build stream

一、问题 Deploying nacos Dockerfile: ruoyi-visual/ruoyi-nacos/Dockerfile… Building image… Preparing build context archive… [>]211/211 files DoneSending build context to Docker daemon… [>] 6.099MB DoneStep 1/8 : FROM openjdk:11---> 5505a9a39df…

chatgpt赋能python:用Python创建股票池

用Python创建股票池 介绍 如果你是一位投资者&#xff0c;你一定知道股票池是什么。它是一个包含一组股票的集合&#xff0c;使投资者能够跟踪和管理他们的投资组合。这些股票可以根据各种因素分类&#xff0c;例如行业&#xff0c;市值&#xff0c;收入增长等。 Python是一…

Oracle的学习心得和知识总结(二十六)|Oracle数据库Real Application Testing测试指南(数据库回放)

目录结构 注&#xff1a;提前言明 本文借鉴了以下博主、书籍或网站的内容&#xff0c;其列表如下&#xff1a; 1、参考书籍&#xff1a;《Oracle Database SQL Language Reference》 2、参考书籍&#xff1a;《PostgreSQL中文手册》 3、EDB Postgres Advanced Server User Gui…

学习HCIP的day.13

目录 IPV6 一、特征-升级点 二、IPV6地址 三、IPV6地址分类 1、单播地址 2、多播地址 四、协议 五、思科配置 1、接口配置IPV6的单播地址 2、IPV6的ACL 3、IPV6的单播路由协议 4、IPV4和IPV6共存 六、华为IPV6配置 1、静态 2、OSPF 3、BGP 4、IPV4和IPV6共存…

我的内网渗透-提权大法

拿到shell之后乱码解决 chcp 65001 #将编码设置为UTF-8的编码 出现这个提示就是切换成功&#xff0c;后面也是可以正常显示的 提权 方法一&#xff1a; 新版本的kali直接getsystem&#xff0c;可以提权成功&#xff08;有时候可以&#xff0c;有时候不可以&#xff09; mete…

chatgpt赋能python:Python循环3次的方法

Python循环3次的方法 循环是编程中经常用到的一个基本操作&#xff0c;可以让相同的代码运行多次。在Python中&#xff0c;循环也是极其重要的&#xff0c;其中最常用的是for和while循环。在本文中&#xff0c;我们将介绍如何使用Python循环3次。 使用for循环 使用for循环是…

电气器件系列三十八:耐压测试仪2

某型号官方资料&#xff1a; 系列耐压测试仪是测量耐压强度的仪器&#xff0c;可以直观、准确、快速地测试各种被测对象的击穿电压、漏电流等电气安全性能指标&#xff0c;并可以作为高压源用来测试元器件和整机性能。 本系列测试仪符合如下标准&#xff1a;家用电器类标准(IE…

响应式网页

解决方案&#xff1a; 媒体查询 max-width 最大宽度 <768 (从大到小) min-width 最小宽度 >768 (从小到大) media(条件){html{background-color: green;} } 需求&#xff1a; 默认网页前景色是灰色屏幕亮度大于等于768px&#xff0c;网页背景色是粉色屏幕亮度大于…

谈谈GPT-4文本代码降本减料引起的质量下降

先是少数用户提出质疑&#xff0c;随后大量网友表示自己也注意到了&#xff0c;还贴出不少证据。 有人反馈&#xff0c;把GPT-4的3小时25条对话额度一口气用完了&#xff0c;都没解决自己的代码问题。 无奈切换到GPT-3.5&#xff0c;反倒解决了。 总结下大家的反馈&#xff0c…

gitlab+jenkins+harbor实现CI/CD(2)——初级

文章目录 一、docker git安装二、jenkins使用步骤创建项目在jenkins主机获取密钥 三、实时触发构建四、整合harbor仓库 一、docker git安装 git安装 yum install -y gitjenkins主机上安装docker-ce [rootvm6 yum.repos.d]# yum install -y docker-ce [rootvm6 ~]# systemctl…