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

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.
 
 #include <iostream>
#include <algorithm>
#include <cstdio>
#include <set>
#include <cstring>
using namespace std;
int a[][];
int n;
int vis[][];
int dx[]={,,-,},dy[]={-,,,};
set<int> se;
int dfs(int x,int y,int s,int num)
{
if(s==)
{
//cout<<num<<endl;
se.insert(num);
return ;
}
for(int i=;i<;i++)
{
int nx=x+dx[i];
int ny=y+dy[i];
if(nx>=&&ny>=&&nx<=&&ny<=&&vis[nx][ny]==)
{
// vis[nx][ny]=1;
dfs(nx,ny,s+,num*+a[nx][ny]);
// vis[nx][ny]=0;
}
}
return ;
}
int main()
{
int i,j;
freopen("in.txt","r",stdin);
memset(vis,,sizeof(vis));
for(i=;i<;i++)
for(j=;j<;j++)
scanf("%d",&a[i][j]);
for(i=;i<;i++)
for(j=;j<;j++)
{
//vis[i][j]=1;
dfs(i,j,,a[i][j]);
//vis[i][j]=0;
}
printf("%d\n",se.size());
// set<int>::iterator a=se.begin();
/*for(;a!=se.end();a++)
{
cout<<*a<<endl;
}*/
}

Hopscotch(POJ 3050 DFS)的更多相关文章

  1. Roads in the North(POJ 2631 DFS)

    Description Building and maintaining roads among communities in the far North is an expensive busine ...

  2. 深度搜索DFS-Lake Counting(POJ NO.2386)

    题目链接POJ NO.2386 解题思路: 这个也是一个dfs 的应用,在书上的例子,因为书上的代码并不全,基本都是函数分块来写,通过这个题目也规范了代码,以后能用函数的就都用函数来实现吧.采用深度优 ...

  3. HDU 5416 CRB and Tree(前缀思想+DFS)

    CRB and Tree Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

  4. [wikioi2144]砝码称重2(另类的dfs)

    题目描述 Description 有n个砝码,现在要称一个质量为m的物体,请问最少需要挑出几个砝码来称? 注意一个砝码最多只能挑一次 输入描述 Input Description 第一行两个整数n和m ...

  5. 【BZOJ】1603: [Usaco2008 Oct]打谷机(水题+dfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1603 这种水题... dfs没话说.. #include <cstdio> #inclu ...

  6. 树的判断(poj nyoj hduoj)

    题目: http://ac.jobdu.com/problem.php?pid=1481 http://acm.nyist.net/JudgeOnline/problem.php?pid=129 ht ...

  7. fjwc2019 D1T3 不同的缩写(dinic+trie+dfs)

    #180. 「2019冬令营提高组」不同的缩写 乍看之下没有什么好的方法鸭.......于是考虑暴力. 长度?二分似乎可行. 于是我们二分最长子串的长度(设为$len$),蓝后暴力查找. 先在每个串内 ...

  8. 蓝桥杯之大臣的旅费(两次dfs)

    Description 很久以前,T王国空前繁荣.为了更好地管理国家,王国修建了大量的快速路,用于连接首都和王国内的各大城市. 为节省经费,T国的大臣们经过思考,制定了一套优秀的修建方案,使得任何一个 ...

  9. 图的基本算法(BFS和DFS)

    图是一种灵活的数据结构,一般作为一种模型用来定义对象之间的关系或联系.对象由顶点(V)表示,而对象之间的关系或者关联则通过图的边(E)来表示. 图可以分为有向图和无向图,一般用G=(V,E)来表示图. ...

随机推荐

  1. css 三角实例

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  2. 去除winXP访问共享的“记住密码”

    控制面板->用户帐户,选择自己的用户,在左侧的管理我的网络密码里有删除选项 控制面板-->用户-->点击你登陆用户-->点击左上角“管理我的网络密码”-->在列表中删除密 ...

  3. wikioi1369 xth 砍树

    题目描述 Description 在一个凉爽的夏夜,xth 和 rabbit 来到花园里砍树.为啥米要砍树呢?是这样滴, 小菜儿的儿子窄森要出生了.Xth这个做伯伯的自然要做点什么.于是他决定带着 r ...

  4. Mysql 创建用户并对其赋予操作权限

    授权命令GRANT 语句的语法如下: GRANT privileges (columns) ON what TO user IDENTIFIEDBY "password" WITH ...

  5. VMware+Ubuntu8.10+Skyeye+gdb实现u-boot源码调试

    系统平台:WindowsXP 虚拟机: VMware Workstation 6.5.0 Ubuntu8.10 安装程序 ubuntu-8.10-desktop-i386.iso 下载地址:http: ...

  6. 【DataStructure】Description and usage of queue

    [Description] A queue is a collection that implements the first-in-first-out protocal. This means th ...

  7. 一步一步学数据结构之n--n(Prim算法)

    在这里说下最小连通网的Prim算法: 而Kruskal算法,http://blog.csdn.net/nethanhan/article/details/10050735有介绍,大家可以去看下! Pr ...

  8. Unity 2D 跑酷道路动起来

    之前做2D的游戏怎样让背景动起来?就想着做成滚屏效果不就行了,今天在网上看到人家做的既简单又方便,唉,忏愧啊!不过还好,下次可以为自己所用了!呵呵 废话就不扯了,新建工程! 1 ,打开Unity 5. ...

  9. iOS多线程及其感悟

    感觉每天都是匆匆忙忙的,每天似乎都是时间不够用一样,可是等真的想要动手敲代码的时候才发现,原来还有好多好多的知识点不是太熟练,所以,人不可以一直感觉自我良好, 有时间就是那种自我感觉良好的心态毁了自己 ...

  10. input输入字母自动大小写转换

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...