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

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

错了N次。。这个题坑点在于只能是五子棋,6子,7子都不行,所以对一个点的某一个方向来说正反都要搜一遍。
而且还要注意是结果是要位于左上角的点。所以可以先将某一列的每一行先找一遍,这样的话得到的结果就一定是左上角的点。
给大家两组测试用例:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 2 1 2 0 0 0 0 0 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 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
输出是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 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 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 1 0 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 1 2 2 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 0 1 2 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
6 1
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<iostream>
using namespace std;
typedef long long LL;
int graph[][];
bool vis[][];
int cnt;
int res,resx,resy;
int dir[][] = {{,},{-,},{,},{,-},{,},{-,-},{-,},{,-}};
bool check(int x,int y,int flag)
{
if(x<||x>||y<||y>||graph[x][y]!=flag) return false;
return true;
}
struct Node
{
int x,y;
int step;
};
Node s;
bool bfs(int x,int y,int flag)
{
Node now;
now.x = x,now.y = y,now.step = ;
Node next;
for(int i=; i<; i++)
{
next.x = now.x+dir[i][];
next.y = now.y +dir[i][];
next.step = now.step+;
while(check(next.x,next.y,flag))
{
next.x+=dir[i][];
next.y+=dir[i][];
next.step++;
}
int step1 = next.step - ;
next.x = now.x+dir[i^][]; ///反方向也要找
next.y = now.y +dir[i^][];
next.step = now.step+;
while(check(next.x,next.y,flag))
{
next.x+=dir[i^][];
next.y+=dir[i^][];
next.step++;
}
int step2 = next.step - ;
if(step1+step2==) return true;
}
return false;
}
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
for(int i=; i<; i++)
{
for(int j=; j<; j++)
{
scanf("%d",&graph[i][j]);
}
}
bool flag = false;
res = ,resx=-,resy=-;
for(int j=; j<&&!flag; j++)
{
for(int i=; i<&&!flag; i++)
{
if(graph[i][j]==)
{
flag = bfs(i,j,);
if(flag)
{
res = ;
resx = i;
resy = j;
}
}
if(graph[i][j]==)
{
flag = bfs(i,j,);
if(flag)
{
res = ;
resx = i;
resy = j;
}
}
}
}
if(res==) printf("0\n");
else printf("%d\n%d %d\n",res,resx,resy);
}
return ;
}

poj 1970(搜索)的更多相关文章

  1. catch that cow POJ 3278 搜索

    catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个 ...

  2. POJ 1970 The Game (DFS)

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

  3. [Vjudge][POJ][Tony100K]搜索基础练习 - 全题解

    目录 POJ 1426 POJ 1321 POJ 2718 POJ 3414 POJ 1416 POJ 2362 POJ 3126 POJ 3009 个人整了一些搜索的简单题目,大家可以clone来练 ...

  4. poj 2251 搜索

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13923   Accepted: 5424 D ...

  5. poj 1011 搜索减枝

    题目链接:http://poj.org/problem?id=1011 #include<cstdio> #include<cstring> #include<algor ...

  6. 生日蛋糕 POJ - 1190 搜索 数学

    http://poj.org/problem?id=1190 题解:四个剪枝. #define _CRT_SECURE_NO_WARNINGS #include<cstring> #inc ...

  7. poj 2531 搜索剪枝

    Network Saboteur Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u ...

  8. POJ 1970 The Game

    The Game Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6886   Accepted: 1763 Descript ...

  9. POJ 3039 搜索??? (逼近)

    思路: 抄的题解 这叫搜索? 难以理解 我觉得就是枚举+逼近 //By SiriusRen #include <cmath> #include <cstdio> #includ ...

随机推荐

  1. Java-JFrame-swing嵌套浏览器步骤

    Java-JFrame-swing嵌套浏览器步骤 一.使用swing嵌套浏览器要实现的功能: 通过java的swing实现在一个窗体中嵌套一个浏览器,可以在这个浏览器中将另一个项目的内容显示出来,只需 ...

  2. Python基础学习总结__Day4

    一.装饰器 前戏: 1.函数即变量 (1)函数名为‘门牌号’即内存地址,加括号开始调用 (2)没有变量调用将清空内存 (3)匿名函数(lambda函数):没有‘门牌号’,需要赋值给变量,否则将会被清空 ...

  3. Party Games UVA - 1610 贪心

    题目:题目链接 思路:排序后处理到第一个不同的字符,贪心一下就可以了 AC代码: #include <iostream> #include <cstdio> #include ...

  4. ACM-ICPC 2015 Shenyang Preliminary Contest B. Best Solver

    The so-called best problem solver can easily solve this problem, with his/her childhood sweetheart. ...

  5. cf 1006E

    #include <iostream> #include <cstdio> #include <cstring> #include <string> # ...

  6. Fiddler证书安装不成功

    Fiddler 抓包https配置 提示creation of the root certificate was not successful 证书安装不成功 原文链接 在使用Fiddler抓包时,我 ...

  7. 使用powershell/vbs自动化模拟鼠标点击操作

    今天想做windows上的自动化,所以才有了模拟鼠标点击的需求,先考虑用powershell实现: 首先先安装一个名为“WASP”免费可用的Powershell扩展程序,下载地址:http://was ...

  8. POJ-3278 广度优先搜索入门

    #include<stdio.h> #include<stdlib.h> struct node{ int x; int s; }s[]; int main(){ ]={}; ...

  9. WCF服务编程——数据契约快速入门

    WCF序列化流程 序列化 默认用户自定义类型(类和结构)并不支持序列化,因为.NET无法判断对象状态是否需要反射到流. 用户自定义类的实例支持序列化 需要添加[Serialazable].若要允许可序 ...

  10. 大数据学习——sparkSql对接hive

    1.   安装mysql 2.   上传.解压.重命名 2.1.  上传 在随便一台有hadoop环境的机器上上传安装文件 su - hadoop rz –y 2.2.  解压 解压缩:apache- ...