Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 6886   Accepted: 1763

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

Source

思路:搜索。

#include<iostream>
using namespace std;
const int dir_x[]={,,,-};
const int dir_y[]={,,,};
void search(int x,int y);
int judge,goal_x,goal_y,board[][];
void search(int x,int y){
for(int i=;i<;i++){
int tmpx=x,tmpy=y,counter=;
int tx=tmpx-dir_x[i],ty=tmpy-dir_y[i];
if(tx>=&&tx<&&ty>=&&ty<&&board[tx][ty]==board[x][y]) continue;
while(tmpx>=&&tmpx<&&tmpy>=&&tmpy<&&board[tmpx][tmpy]==board[x][y]){
counter++;
tmpx+=dir_x[i];
tmpy+=dir_y[i];
}
if(counter==){
judge=board[x][y];
goal_x=x+; goal_y=y+;
return;
}
}
return;
}
int main(){
int t;cin>>t;
while(t--){
for(int i=;i<;i++)
for(int j=;j<;j++)
cin>>board[i][j];
judge=;
for(int i=;i<;i++){
if(judge!=) break;
for(int j=;j<;j++){
if(judge!=) break;
if(board[i][j]==) continue;
search(i,j);
}
}
cout<<judge<<endl;
if(judge==)cout<<goal_x<<" "<<goal_y<<endl;
else if(judge==) cout<<goal_x<<" "<<goal_y<<endl;
}
}

POJ 1970 The Game的更多相关文章

  1. POJ 1970 The Game (DFS)

    题目链接:http://poj.org/problem?id=1970 题意: 有一个19 × 19 的五子棋棋盘,其中“0”代表未放入棋子,“1”代表黑色棋子,”2“代表白色棋子,如果某方的棋子在横 ...

  2. poj 1970(搜索)

    The Game Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6247   Accepted: 1601 Descript ...

  3. 【POJ - 1970】The Game(dfs)

    -->The Game 直接中文 Descriptions: 判断五子棋棋局是否有胜者,有的话输出胜者的棋子类型,并且输出五个棋子中最左上的棋子坐标:没有胜者输出0.棋盘是这样的,如图 Samp ...

  4. POJ题目排序的Java程序

    POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...

  5. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  6. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  7. poj分类

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  8. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

  9. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

随机推荐

  1. md5加密、Des加密对称可逆加密、RSA非对称可逆加密、https单边验证、银行U盾双边认证

    1.md5不可逆的加密方式,加密成一个32位的字符串.算法是公开的,任何语言的加密结果都是一样的.总有可能是重复的.     用途:             (1)防止明文存储:可以用作密码加密    ...

  2. 关于加减和es6

    console.log(1+ "2"+"2");   //对于加法来说,如果只有一个操作数是字符串,则将另一个操作数也转换为字符串,然后将两者拼接,为122 c ...

  3. HTTP常见面试题

    转自:http://www.cnblogs.com/Java3y/p/8444033.html Http与Https的区别: Http与Https的区别: HTTP 的URL 以http:// 开头, ...

  4. Zynq7000系列之芯片引脚功能综述

    很多人做了很久的FPGA,知道怎么去给信号分配引脚,却对这些引脚的功能及其资源限制知之甚少:在第一章里对Zynq7000系列的系统框架进行了分析和论述,对Zynq7000系列的基本资源和概念有了大致的 ...

  5. 分布式缓存系统Memcached[分享]

    个人网站:http://www.51pansou.com memcached视频下载:memcached视频教程 memcached源码下载:memcached源码 Memcached是什么? Mem ...

  6. (转)淘淘商城系列——商品搜索功能Service实现

    http://blog.csdn.net/column/details/15737.html 首先我们在taotao-search-interface工程中新建一个SearchService接口,并在 ...

  7. 当From窗体中数据变化时,使用代码获取数据库中的数据然后加入combobox中并且从数据库中取得最后的结果

    private void FormLug_Load(object sender, EventArgs e) { FieldListLug.Clear();//字段清除 DI = double.Pars ...

  8. list查询棚舍面积的时候,所有棚舍面积的value都是一样的

    解决办法 将pickingid在查list之前set到对象中,通过id来匹配查询 具体代码: FarmHouse farmHouse=new FarmHouse(); farmHouse.setPic ...

  9. 调用微信扫一扫功能,踩坑'invalid signature'

    在vue项目中,调用微信扫一扫功能,在安卓系统下完全正常,ios系统下却报错'invalid signature'的错误,这可能令许多小伙伴困惑,经过查询大量博客相关资料,才找到了解决的方法. 原因: ...

  10. 支持向量机(SVM)原理浅析

    因为网页博客输入公式很麻烦,所以就在word上面写了,然后截图发上来. 后续关于SVM和FC在深度学习当中得使用对比分析,我再补充.