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. linux和windows系统的区别

    在21世纪的今天,互联网可以说是当代发展最为迅速的行业,举个很简单的例子,现在的我们不论什么年龄阶层,几乎人手都有一部手机,上面的某博,某音,末手等软件,更是受到多数人的热爱,并且人们不仅仅用其来消遣 ...

  2. 【PAT甲级】1003 Emergency (25 分)(SPFA,DFS)

    题意:n个点,m条双向边,每条边给出通过用时,每个点给出点上的人数,给出起点终点,求不同的最短路的数量以及最短路上最多能通过多少人.(N<=500) AAAAAccepted code: #in ...

  3. 中国5G,如何避免重复投资?

    前不久,工信部正式向中国移动.中国联通.中国电信发放5G商用牌照,此举意味着中国提前启动5G商用计划,随之而来的,将会是运营商.设备商大规模的投资.相关数据机构预测,三大运营商2019年预计会投入30 ...

  4. C++11常用特性介绍——constexpr变量

    一.constexpr变量 1)将变量声明为constexpr类型以便由编译器来验证变量的值是否为一个常量表达式,声明为constexpr的变量一定是一个常量,而且必须用常量表达式来初始化,如: in ...

  5. js中的关键字与保留字

    关键字就是指:js中用到的单词,比如var : function: 保留字是指:js以后可能会发展成为关键字的,先保留起来不让你用.比如class,要是给一个对象添加class:obj.classNa ...

  6. ES 创建mapping

    mapping的写入与查看首先创建一个索引: curl -XPUT "http://erp2.es.kd1.pagoda.com.cn:80/erp_stock_index"{&q ...

  7. centos解决bash: telnet: command not found...&& telnet: connect to address 127.0.0.1: Connection refused拒绝连接

    检查telnet是否已安装: [root@hostuser src]# rpm -q telnet-serverpackage telnet-server is not installed[root@ ...

  8. Dart语言学习(十四) Dart泛型

    什么是泛型? 通俗理解:泛型就是解决 类 接口 方法的复用性.以及对不特定数据类型的支持(类型校验) 如下代码,只能返回string类型的数据 String getData(String value) ...

  9. Java入门笔记 01-Java基础语法

    一.数据类型和运算符 1.注释可以提高程序的可读性.可划分为 单行注释 // 多行注释 /.../ 文档注释 /**...*/ 2.标识符的命名规则: 标识符必须以字母.下划线_.美元符号$开头. 标 ...

  10. 企业行业分类数据库JSON

    这篇文章主要介绍了 企业信息中选择行业类型,常用在企业注册,入驻填写企业信息等. JSON: [{"id":1001,"name":"IT服务&quo ...