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 ...
随机推荐
- NOIP2013 乌龟棋
描述 小明过生日的时候,爸爸送给他一副乌龟棋当作礼物. 乌龟棋的棋盘是一行N个格子,每个格子上一个分数(非负整数).棋盘第1格是唯一的起点,第N格是终点,游戏要求玩家控制一个乌龟棋子从起点出发走到终点 ...
- 万门大学Python零基础10天进阶班视频教程
点击了解更多Python课程>>> 万门大学Python零基础10天进阶班视频教程 课程简介: 旨在通过两周的学习,让学生不仅能掌握python编程基础从而进行计算机程序的开发, 还 ...
- ubuntu中卸载没有安装完全的软件包
sudo apt-get autoclean sudo apt-get clean sudo apt-get autoremove
- Persona5
65536K Persona5 is a famous video game. In the game, you are going to build relationship with your ...
- github FATAL:unable to access 'https://github.com/...: Failed to connect to github.com:443; No error
今天整理github,初次使用,很多都不懂,所以遇到了克隆失败的问题,研究了大半天,后来..... 打开Git Bash,克隆已有工程到本地: $ git clone https://github.c ...
- 函数名&函数名取地址
有时看到如下的代码: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 /*****************************/ #includ ...
- install mongodb on macos
Update Homebrew’s package database. In a system shell, issue the following command: brew update 2 In ...
- luogu2765 魔术球问题
发现好像没人来证明贪心啊--那我来写一下它的证明 欲证明:放一个数在已有的柱上(如果可以)总是比新开一个柱更优的 假如已经放了x1..x2....xu..xv..xw.... 现在我要放xx 我有两种 ...
- python week08 并发编程之多线程--实践部分
一. threading模块介绍 multiprocess模块的完全模仿了threading模块的接口,二者在使用层面,有很大的相似性,因而不再详细介绍 官网链接:https://docs.pytho ...
- Leetcode 430.扁平化多级双向链表
扁平化多级双向链表 您将获得一个双向链表,除了下一个和前一个指针之外,它还有一个子指针,可能指向单独的双向链表.这些子列表可能有一个或多个自己的子项,依此类推,生成多级数据结构,如下面的示例所示. 扁 ...