【POJ - 1970】The Game(dfs)
-->The Game
直接中文
Descriptions:
判断五子棋棋局是否有胜者,有的话输出胜者的棋子类型,并且输出五个棋子中最左上的棋子坐标;没有胜者输出0。棋盘是这样的,如图

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
题目链接:
https://vjudge.net/problem/POJ-1970
五子棋,但是有点小坑,不能六子连在一起,简单说就是只能5颗棋子在一起
从上到下、从左到右遍历棋盘,当位置(x, y)有棋子时,则从该位置开始dfs,加上搜索的方向为向右(x, y+1),向下(x+1, y),右下(x+1, y+1),右上(x, y-1),所以如果搜索的结果符合获胜的条件,则(x, y)就为最左上的位置。
除了坐标之外,还要加上方向vist[i][j][d],表示在坐标(i, j)的d方向是否搜索过。
AC代码:
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 25
using namespace std;
int T;
int n=;
int cnt;
int vis[Maxn][Maxn][Maxn];//vist[i][j][d] 坐标(i, j)的d方向是否搜索过
int mp[Maxn][Maxn];//棋盘
int dt[][] = {{-, }, {, }, {, }, {, }}; //方向为右上、右、右下、下
void dfs(int x,int y,int k,int people)//(x,y) k方向 people哪个人的棋子
{
vis[x][y][k]=;
int dx=x+dt[k][];
int dy=y+dt[k][];
if(dx>=&&dy>=&&dx<=n&&dy<=n&&mp[dx][dy]==people)
{
cnt++;
dfs(dx,dy,k,people);
}
}
int main()
{
cin>>T;
while(T--)
{
int f=;//初始化
MEM(vis,);
MEM(mp,);
for(int i=; i<=n; i++)//存图
for(int j=; j<=n; j++)
cin>>mp[i][j];
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(mp[i][j])//不为0,开始搜
{
int people=mp[i][j];//看看是谁下的棋
for(int k=;k<;k++)//四个方向
{
if(!vis[i][j][k])
{
cnt=;//棋子的个数
dfs(i,j,k,people);
//5颗棋子,防止左上角之前还有一个棋子
if(cnt==&&mp[i-dt[k][]][j-dt[k][]]!=people)
{
f=;
cout<<people<<endl;
cout<<i<<" "<<j<<endl;
break;
}
}
}
}
}
}
if(f==)
cout<<""<<endl;
}
}
【POJ - 1970】The Game(dfs)的更多相关文章
- 【POJ - 3984】迷宫问题(dfs)
-->迷宫问题 Descriptions: 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0 ...
- 【POJ - 1321】棋盘问题 (dfs)
棋盘问题 Descriptions: 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘 ...
- BZOJ 2296【POJ Challenge】随机种子(构造)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2296 [题目大意] 给出一个数x,求一个10的16次以内的数使得其被x整除并且数字包含 ...
- 【POJ 1273】Drainage Ditches(网络流)
一直不明白为什么我的耗时几百毫秒,明明差不多的程序啊,我改来改去还是几百毫秒....一个小时后:明白了,原来把最大值0x3f(77)取0x3f3f3f3f就把时间缩短为16ms了.可是为什么原来那样没 ...
- 【POJ - 2386】Lake Counting (dfs+染色)
-->Lake Counting 直接上中文了 Descriptions: 由于近日阴雨连天,约翰的农场中中积水汇聚成一个个不同的池塘,农场可以用 N x M (1 <= N <= ...
- 【POJ - 3669】Meteor Shower(bfs)
-->Meteor Shower Descriptions: Bessie听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平 ...
- 【 Gym 101116K 】Mixing Bowls(dfs)
BUPT2017 wintertraining(15) #4H Gym - 101116K 题意 给定一个菜谱,大写的单词代表混合物,小写的代表基础原料.每个混合物由其它混合物或基础原料组成,不会间接 ...
- 【POJ 2251】Dungeon Master(bfs)
BUPT2017 wintertraining(16) #5 B POJ - 2251 题意 3维的地图,求从S到E的最短路径长度 题解 bfs 代码 #include <cstdio> ...
- 【POJ - 1661】Help Jimmy (动态规划)
Help Jimmy Descriptions: "Help Jimmy" 是在下图所示的场景上完成的游戏. 场景中包括多个长度和高度各不相同的平台.地面是最低的平台,高度为零,长 ...
随机推荐
- 【UVALive-7040F】Color
题目大意:给定一个长度为 N 的序列,现有 M 种颜色,选出一些颜色对这个序列进行染色,要求相邻元素颜色不相同.求最终序列恰好有 K 种不同颜色的染色方案数,结果对1e9+7取模. 题解:二项式反演 ...
- git命令行提交流程
一.顺利提交无冲突情况(diff->add->fetch->pull->commit->push) 1.git status 查看状态 2. git diff head ...
- kickstart批量装机脚本
#!/bin/bash #安装必备的软件 yum -y install dhcp tftp-server tftp xinetd syslinux vsftpd yum -y install *kic ...
- python一些方便excel行操作的函数(一)
import collections class headhandler(): def __init__(self,mylist): self.mystorage={} self.mylist = m ...
- springboot的application.yml配置详解
https://www.cnblogs.com/lqtbk/p/9843401.html https://blog.csdn.net/yelllowcong/article/details/79216 ...
- 小米 oj 找到第N个数字||
Mycode: #include<iostream> #include<stdio.h> #include<string.h> using namespace st ...
- mysql查询字段中含有中文
查询mysql数据库中字段中含有中文使用正则表达式: 例如: select create_time,nickname from eb_engineer where not(nickname regex ...
- Django admin site应用
django自带的admin后台管理,可以实现对数据库表的增删改查,用起来十分方便.其使用和配置主要分为三个步骤: 1,创建超级用户 需要创建超级用户来登陆admin后台系统,在命令行中输入 pyth ...
- pi币--π币--手机离线式挖矿软件--pi中文教程!
Pi Network派型网络,国外热度很高手机移动式挖矿软件 一个新出的手机移动式挖矿软件,在国外热度很高,国内玩的人目前很少.项目团队成员均来自斯坦福大学,三个创始人斯坦福博士教授,现在处于挖矿第一 ...
- 关于jenkins
启动不了时可更改端口 java -jar jenkins.war –httpPort=8090