Hopscotch

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6761   Accepted: 4354

Description

The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered boxes into which to hop, the cows create a 5x5 rectilinear grid of digits parallel to the x and y axes.

They then adroitly hop onto any digit in the grid and hop forward,
backward, right, or left (never diagonally) to another digit in the
grid. They hop again (same rules) to a digit (potentially a digit
already visited).

With a total of five intra-grid hops, their hops create a six-digit integer (which might have leading zeroes like 000201).

Determine the count of the number of distinct integers that can be created in this manner.

Input

* Lines 1..5: The grid, five integers per line

Output

* Line 1: The number of distinct integers that can be constructed

Sample Input

1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 2 1
1 1 1 1 1

Sample Output

15

Hint

OUTPUT DETAILS:
111111, 111112, 111121, 111211, 111212, 112111, 112121, 121111,
121112, 121211, 121212, 211111, 211121, 212111, and 212121 can be
constructed. No other values are possible.

题意:给一个5x5的矩阵,从矩阵的任意一个位置开始搜索6次,(允许方向为上下左右四个方向),问一可以产生多少个不同的序列

#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;
char a[][];
int dir[][]={{,-},{,},{,},{-,}};
set<string>p;
string s; int check(int x,int y)
{
if(x>=&&x<&&y>=&&y<)
return ;
else
return ;
}
void dfs(int x,int y,int n)
{
if(n>=)
{
p.insert(s);
return ;
}
for(int i=;i<;i++)
{
int dx,dy;
dx=x+dir[i][];
dy=y+dir[i][];
if(check(dx,dy)==)
continue;
s=s+a[dx][dy];
dfs(dx,dy,n+);
s.erase(n);
}
return ;
}
int main()
{
for(int i=;i<;i++)
{
for(int j=;j<;j++)
cin>>a[i][j];
}
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
s.clear();
dfs(i,j,);
}
}
cout<<p.size()<<endl;
// set<string>::iterator it;
// for(it=p.begin();it!=p.end();it++)
// {
// cout<<*it<<endl;
// }
}

POJ 3050 Hopscotch 四方向搜索的更多相关文章

  1. poj 3050 Hopscotch DFS+暴力搜索+set容器

    Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2774 Accepted: 1940 Description ...

  2. POJ 3050 Hopscotch【DFS带回溯】

    POJ 3050 题意: 1.5*5的方阵中,随意挑一格,记住这个格子的数字 2.可以上下左右走,走5次,每走一次记录下所走格子的数字 3.经过以上步骤,把所得6个数字连起来,形成一串数字.求共可以形 ...

  3. POJ -3050 Hopscotch

    http://poj.org/problem?id=3050 给定一个5×5矩阵,问选6个数的不同排列总数是多少! 二维的搜索,注意要判重,数据量很小,直接用map就好. #include<cs ...

  4. POJ 3050 Hopscotch 水~

    http://poj.org/problem?id=3050 题目大意: 在一个5*5的格子中走,每一个格子有个数值,每次能够往上下左右走一格,问走了5次后得到的6个数的序列一共同拥有多少种?(一開始 ...

  5. POJ 3050 Hopscotch DFS

    The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of num ...

  6. POJ 3050 Hopscotch(dfs,stl)

    用stack保存数字,set判重.dfs一遍就好.(或者编码成int,快排+unique #include<cstdio> #include<iostream> #includ ...

  7. POJ 3126 Prime Path 广度优先搜索 难度:0

    http://poj.org/problem?id=3126 搜索的时候注意 1:首位不能有0 2:可以暂时有没有出现在目标数中的数字 #include <cstdio> #include ...

  8. Hopscotch(POJ 3050 DFS)

    Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2845   Accepted: 1995 Descrip ...

  9. 【POJ - 3050】Hopscotch (dfs+回溯)

    -->Hopscotch 这接写中文了 Descriptions: 奶牛们以一种独特的方式玩孩子们的跳房子游戏. 奶牛们创造了一个5x5的格子 他们熟练地跳上其中的一个格子,可以前后左右地跳(不 ...

随机推荐

  1. 学习笔记(20)- Google LaserTagger

    参考文章:推断速度达seq2seq模型的100倍,谷歌开源文本生成新方法LaserTagger 论文地址:https://research.google/pubs/pub48542/ 开源地址:htt ...

  2. Nginx 七层反向代理

    目录 1.代理 2.正向代理 3.反向代理 4.Nginx 反向代理 5.Nginx 反向代理相关指令介绍 ①.listen ②.server_name ③.location ④.proxy_pass ...

  3. python中的异常处理:厌而不舍

      什么是异常? ------异常:不正常的情况 异常即是一个事件,该事件会在程序执行过程中发生,影响了程序的正常执行.一般情况下,在Python无法正常处理程序时就会发生一个异常. 异常是Pytho ...

  4. vue element多图上传

    最近项目需要优化图片上传,由单个改成多个,这里记录下自己遇到的一些问题和解决方法 本以为是传全部图片到后台,然后统一处理,但后面在Network中发现upload组件其实还是单一上传,那只能依照它的方 ...

  5. ALSA 有关文档

    Alsa项目的官方网址:http://www.alsa-project.org/ Alsa LIB API Reference:http://www.alsa-project.org/alsa-doc ...

  6. BKP寄存器

    STM32的BKP: 备份寄存器是42个16位的寄存器,可用来存储84个字节的用户应用程序数据.他们处在备份域里,当VDD电源被切断,他们仍然由VBAT维持供电.当系统在待机模式下被唤醒,或系统复位或 ...

  7. 「Luogu P3168 [CQOI2015]任务查询系统」

    介绍本题的两种做法: 方法1 前置芝士 线段树:一个很重要的数据结构. 树状数组:一个很重要的数据结构. 具体实现 区间修改,单点查询很容易就会想到树状数组了,至于查询前k个数的和又可以丢给权值线段树 ...

  8. 技术|Android安装包极限优化

    版权声明 1.本文版权归原作者所有,转载需注明作者信息及原文出处. 2.本文作者:赵裕(vimerzhao),永久链接:https://github.com/vimerzhao/vimerzhao.g ...

  9. uniGUI之uniPanel(20)

    1]uniPanel常用设置: 2]多个uniPanel在一个uniPanel里显示 uniPanel常用设置: 2]多个uniPanel在一个uniPanel里显示 uniPanel0.Alignm ...

  10. SpringBoot 集成Spring JDBC

    (1)在pom.xml中添加依赖 <!--spring-jdbc的依赖--> <dependency> <groupId>org.springframework.b ...