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
  2. 1 1 1 1 1
  3. 1 1 1 1 1
  4. 1 1 1 2 1
  5. 1 1 1 1 1

Sample Output

  1. 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次,(允许方向为上下左右四个方向),问一可以产生多少个不同的序列

  1. #include<iostream>
  2. #include<string.h>
  3. #include<string>
  4. #include<algorithm>
  5. #include<queue>
  6. #include<set>
  7. using namespace std;
  8. char a[][];
  9. int dir[][]={{,-},{,},{,},{-,}};
  10. set<string>p;
  11. string s;
  12.  
  13. int check(int x,int y)
  14. {
  15. if(x>=&&x<&&y>=&&y<)
  16. return ;
  17. else
  18. return ;
  19. }
  20. void dfs(int x,int y,int n)
  21. {
  22. if(n>=)
  23. {
  24. p.insert(s);
  25. return ;
  26. }
  27. for(int i=;i<;i++)
  28. {
  29. int dx,dy;
  30. dx=x+dir[i][];
  31. dy=y+dir[i][];
  32. if(check(dx,dy)==)
  33. continue;
  34. s=s+a[dx][dy];
  35. dfs(dx,dy,n+);
  36. s.erase(n);
  37. }
  38. return ;
  39. }
  40. int main()
  41. {
  42. for(int i=;i<;i++)
  43. {
  44. for(int j=;j<;j++)
  45. cin>>a[i][j];
  46. }
  47. for(int i=;i<;i++)
  48. {
  49. for(int j=;j<;j++)
  50. {
  51. s.clear();
  52. dfs(i,j,);
  53. }
  54. }
  55. cout<<p.size()<<endl;
  56. // set<string>::iterator it;
  57. // for(it=p.begin();it!=p.end();it++)
  58. // {
  59. // cout<<*it<<endl;
  60. // }
  61. }

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. Codeforces Round #600 (Div. 2) - D. Harmonious Graph(并查集)

    题意:对于一张图,如果$a$与$b$连通,则对于任意的$c(a<c<b)$都有$a$与$c$连通,则称该图为和谐图,现在给你一张图,问你最少添加多少条边使图变为和谐图. 思路:将一个连通块 ...

  2. MySQL 远程连接问题 (Linux Server)

    Mysql Workbench 连接Ubuntu上的Mysql时报如下错误: 原因:查看  /etc/mysql/mysql.conf.d/mysqld.cnf # # Instead of skip ...

  3. redhat 7.6 iptables 配置

    1.查看iptables默认表(filter) iptables -L -n 2.iptables 默认内链(filter)表三种: INPUT:处理进入防火墙的数据包 FORWARD:源自其他计算机 ...

  4. php 基础 获取远程连接

    1 file_get_contents get $opts = array( 'http'=>array( 'method'=>"GET", 'timeout'=> ...

  5. 解决EFCore缓存机制导致的数据查询错误问题

    如题,在对同一个Context连续进行相同条件的查询时,会触发EFCore的缓存机制,如果这个过程中数据发生了变化,则会出现错误. 例如:有两个Context实例,一个负责查询,一个负责增删改, A_ ...

  6. Java面向对象编程 -1

    面向对象简介 C语言是面向过程开发的代表 C++ 或者Java 是面向对象的编程语言 所谓的面向过程指的是面对于一个问题的解决方案,更多的情况下是不会做出重用的设计思考的. 而面向对象的主要设计形式是 ...

  7. 科普:为什么 String hashCode 方法选择数字31作为乘子

    作者:coolblog 此文章转载自:https://segmentfault.com/a/1190000010799123 1. 背景 某天,我在写代码的时候,无意中点开了 String hashC ...

  8. SPI接口的FLASH

    SPI flash W25Qxx: W25Q系列的spiflash.每页(Page)256B,每16个page为一个sector(扇区=4KB),每16个扇区为一个block(块=64KB) W25Q ...

  9. GsonUtils.getGson().fromJson() 转泛型集合用法

    //计算其他收费 List<QiTaFree> qiTaFreeList = GsonUtils.getGson().fromJson(exhiMain.getQiTaFressJson( ...

  10. 莫烦 - Pytorch学习笔记 [ 一 ]

    1. Numpy VS Torch #相互转换 np_data = torch_data.numpy() torch_data = torch.from_numpy(np_data) #abs dat ...