poj 1970(搜索)
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 6247 | Accepted: 1601 |
Description
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
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
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(搜索)的更多相关文章
- catch that cow POJ 3278 搜索
catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个 ...
- POJ 1970 The Game (DFS)
题目链接:http://poj.org/problem?id=1970 题意: 有一个19 × 19 的五子棋棋盘,其中“0”代表未放入棋子,“1”代表黑色棋子,”2“代表白色棋子,如果某方的棋子在横 ...
- [Vjudge][POJ][Tony100K]搜索基础练习 - 全题解
目录 POJ 1426 POJ 1321 POJ 2718 POJ 3414 POJ 1416 POJ 2362 POJ 3126 POJ 3009 个人整了一些搜索的简单题目,大家可以clone来练 ...
- poj 2251 搜索
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13923 Accepted: 5424 D ...
- poj 1011 搜索减枝
题目链接:http://poj.org/problem?id=1011 #include<cstdio> #include<cstring> #include<algor ...
- 生日蛋糕 POJ - 1190 搜索 数学
http://poj.org/problem?id=1190 题解:四个剪枝. #define _CRT_SECURE_NO_WARNINGS #include<cstring> #inc ...
- poj 2531 搜索剪枝
Network Saboteur Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u ...
- POJ 1970 The Game
The Game Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6886 Accepted: 1763 Descript ...
- POJ 3039 搜索??? (逼近)
思路: 抄的题解 这叫搜索? 难以理解 我觉得就是枚举+逼近 //By SiriusRen #include <cmath> #include <cstdio> #includ ...
随机推荐
- vue 配置多页面应用
前言: 本文基于vue 2.5.2, webpack 3.6.0(配置多页面原理类似,实现方法各有千秋,可根据需要进行定制化) vue 是单页面应用.但是在做大型项目时,单页面往往无法满足我们的需求, ...
- PHP将unicode转utf8最简法
最近开发时遇到Unicode编码问题,找了半天才知道PHP并没有Unicode转码函数,终于发现用一行PHP代码解决的方案: $str = '{"success":true,&qu ...
- 【php】 phpword下载文件问题
这个问题是在 科锐国际 工作过程中发现的 word文档的名字(有汉字和空格)在windows系统上遍历是查不到文件的,但是在linux系统上市可以的压缩包里面的中文名word文档,如果出现汉字和空格, ...
- pandas处理较大数据量级的方法 - chunk,hdf,pkl
前情提要: 工作原因需要处理一批约30G左右的CSV数据,数据量级不需要hadoop的使用,同时由于办公的本本内存较低的缘故,需要解读取数据时内存不足的原因. 操作流程: 方法与方式:首先是读取数据, ...
- python中打印金字塔和九九乘法表的几种方法
# 打印九九乘法表for i in range(1,10): for j in range(1,i+1): # x=i*j # print(i,'*',j,'=',x,end=' ') print(' ...
- Running OOM killer script for process 32248 for Solr on port 8983
Running OOM killer script for process 32248 for Solr on port 8983 分析1 https://blog.csdn.net/qq_41665 ...
- HDU:5040-Instrusive
Instrusive Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Proble ...
- bash之条件测试if/else
bash之条件测试: if/then结构 条件测试(CONDITION): test EXPRESSION:测试条件表达式正确否 [ EXPRE ...
- 串口编程的相关API函数
用户使用函数CreateFile()创建与指定串口相关联的文件,然后可以使用该函数返回的文件句柄进行串口参数设置.• 01 HANDLE hModem; //定义串口句柄02 hModem=Creat ...
- 谋哥:搞APP,做得累的都不对!
最近谋哥(微信viyi88)我刚加入“秦王会”,思想收到猛烈地冲击,各位大佬的思维有时候会让我大脑短路,收获不少.同时,我也慢慢发现我一直平静的 心开始浮躁,我发现苗头不对,于是开始静下心来.静下心, ...