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

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.
1.对于上面的每一组数,刚开始是以字符串处理的,,后来看了一下别人的博客,
才发现直接十进制数的大小不同可以省掉很多麻烦
2.重点在于set集合的使用,,其有去重功能,,貌似白书上介绍过
#include <iostream>

#include<cstdio>

#include<set>

#include<cstring>

using namespace std;

int a[7][7];

int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};

set<int> q;

int dfs(int step,int x,int y,int v)

{

     if(step==6)

         q.insert(v);

     else

            for(int i=0;i<=3;i++)

            {

                 int kx=x+dx[i];

                 int ky=y+dy[i];

                 if(kx>=1&&kx<=5&&ky>=1&&ky<=5)

                   dfs(step+1,kx,ky,v*10+a[kx][ky]);

            }

    return 0;

}

int main()

{

    for(int i=1;i<=5;i++)

        for(int j=1;j<=5;j++)

          scanf("%d",&a[i][j]);

    for(int i=1;i<=5;i++)

        for(int j=1;j<=5;j++)

             dfs(1,i,j,a[i][j]);

    printf("%d\n",q.size());

    return 0;

}

poj 3050 Hopscotch DFS+暴力搜索+set容器的更多相关文章

  1. POJ 3050 Hopscotch 四方向搜索

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

  2. 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 ...

  3. POJ 3050 Hopscotch(dfs,stl)

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

  4. POJ 3050 Hopscotch【DFS带回溯】

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

  5. hdu 1427 速算24点 dfs暴力搜索

    速算24点 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem De ...

  6. ACM: Gym 100935G Board Game - DFS暴力搜索

    Board Game Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u  Gym 100 ...

  7. poj 2718 Smallest Difference(暴力搜索+STL+DFS)

    Smallest Difference Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6493   Accepted: 17 ...

  8. POJ -3050 Hopscotch

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

  9. POJ 3050 Hopscotch 水~

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

随机推荐

  1. linux的安装和配置

    转载:https://www.cnblogs.com/hhaahh/p/10404093.html 1.VMware简介 此软件是一个虚拟的pc机软件,可以在现有操作系统中虚拟出一个新的硬件环境,以此 ...

  2. drf序列化及反序列化

    假如把drf看做一个汉堡包,我们之前讲的模块属于汉堡包前面的盖盖(请求模块.渲染模块)和底底(异常模块.解析模块.响应模块),但是真正中间的夹心没有讲,那么今天我就和大家来看一下汉堡包的夹心(序列化及 ...

  3. 怎样理解Node接口 / ParentNode接口 / ChildNode接口

    ParentNode 和 ChildNode可以理解为是Node的子集, 它对一些具有父节点或子节点的节点提供了一些额外的方法和属性, 比如: 1. 继承了ParentNode的接口有: 元素节点 / ...

  4. 怎样理解 Vue 项目的目录结构?

      Vue 项目的目录结构如下, 我们将会在后面逐个去了解它们的作用: 01. build - 存储项目构建相关的代码, 比如 webpack. 02. config - Vue 的配置目录,包括端口 ...

  5. 解决EntityFramework与System.ComponentModel.DataAnnotations命名冲突

    比如,定义entity时指定一个外键, [ForeignKey("CustomerID")] public Customer Customer { get; set; } 编译时报 ...

  6. WCF寄宿windows服务一

    如果只是寄宿单个wcf服务,方法很简单,步骤:1.创建好一个windows服务.关于windows服务内容见:http://www.cnblogs.com/zhaow/p/7866916.html2. ...

  7. 你真的知道em和rem的区别吗?

    前言 em 和 rem 都是相对单位,在使用时由浏览器转换为像素值,具体取决于您的设计中的字体大小设置. 如果你使用值 1em 或 1rem,它可以被浏览器解析成 从16px 到 160px 或其他任 ...

  8. mysql双yes但是同步延时问题

    今天发现在153服务器insert一条数据,然后查看从库154和162都没有这条数据,但是在154和162执行show slave status  显示的双yes   后来重启了153 154 162 ...

  9. shell脚本视频学习2

    一.函数 1.函数格式 2.函数传入参数 3.手动输入函数中的参数 4.函数返回值 成功返回0,失败返回1 5.输入一个目录,判断目录是否存在,如果不存在则给出提示,如果存在则提示输入要创建的文件名, ...

  10. java开发环境构建

    一. 基本工具安装 1. 配置终端命令别名 vim ~/.bash_profile *********************************************** # for colo ...