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.

  题意:

    在5 * 5的方格里跳房子,起点是任意位置。将跳过的数连起来组成一个5位数(前导零可能),问一共能组成多少个数字?

 #include<iostream>
#include <set>
#include<cmath>
using namespace std; int HS[][];
int ans;
int xs[] = {,-,,};
int ys[] = {,,,-};
set<int> s; void process(int row,int col,int count,int temp)
{
int x,y; temp += HS[row][col]*pow(*1.0,count); if(count == )
{
if(s.find(temp) == s.end())
{
ans++;
s.insert(temp);
} return;
} for(int i = ; i < ; i++)
{
y = row + xs[i];
x = col + ys[i];
if(y < || y > || x < || x > )
continue;
else
process(y,x,count+,temp);
}
} int main()
{
for (int i = ; i < ; ++i)
{
for (int j = ; j < ; j++)
scanf("%d",&HS[i][j]);
}
s.clear();
ans = ; for(int i = ; i < ; i++)
for(int j = ; j < ; j++)
process(i,j,,); cout<<ans<<endl; //这里可以更换为s.size()作为答案
return ;
} //set的使用方法:http://blog.csdn.net/yas12345678/article/details/52601454
//

POJ 3050 Hopscotch DFS的更多相关文章

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

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

  2. POJ 3050 Hopscotch(dfs,stl)

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

  3. POJ 3050 Hopscotch【DFS带回溯】

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

  4. POJ -3050 Hopscotch

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

  5. POJ 3050 Hopscotch 水~

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

  6. POJ 3050 Hopscotch 四方向搜索

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

  7. POJ 3050 枚举+dfs+set判重

    思路: 枚举+搜一下+判个重 ==AC //By SiriusRen #include <set> #include <cstdio> using namespace std; ...

  8. POJ.3172 Scales (DFS)

    POJ.3172 Scales (DFS) 题意分析 一开始没看数据范围,上来直接01背包写的.RE后看数据范围吓死了.然后写了个2^1000的DFS,妥妥的T. 后来想到了预处理前缀和的方法.细节以 ...

  9. Hopscotch(POJ 3050 DFS)

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

随机推荐

  1. Linux:sheel脚本for的用法,及日期参数+1day用法

    记录下shell的for的用法,及参数是日期的情况下,该日期+1day的用法: #!/usr/bin/env bash source /app/catt/login.sh p_days="2 ...

  2. POJ-2253 Frogger---最短路变形&&最大边的最小值

    题目链接: https://vjudge.net/problem/POJ-2253 题目大意: 青蛙A想访问青蛙B,必须跳着石头过去,不幸的是,B所在的石头太远了,需要借助其他的石头,求从A到B的路径 ...

  3. [转]Python UnicodeEncodeError: 'gbk' codec can't encode character 解决方法

    使用Python写文件的时候,或者将网络数据流写入到本地文件的时候,大部分情况下会遇到:UnicodeEncodeError: 'gbk' codec can't encode character ' ...

  4. JS面向对象之原型链

      对象的原型链 只要是对象就有原型 原型也是对象 只要是对象就有原型, 并且原型也是对象, 因此只要定义了一个对象, 那么就可以找到他的原型, 如此反复, 就可以构成一个对象的序列, 这个结构就被成 ...

  5. 机器学习:scipy和sklearn中普通最小二乘法与多项式回归的使用对

    相关内容连接: 机器学习:Python中如何使用最小二乘法(以下简称文一) 机器学习:形如抛物线的散点图在python和R中的非线性回归拟合方法(以下简称文二) 有些内容已经在上面两篇博文中提到了,所 ...

  6. opencv2.4.9卸载安装

    1.安装opencv2.4.9过程中遇到的问题. 1.使用 sudo apt-get install libopencv-dev 安装OpenCV 2.4.9 发现版本为2.4.8,故卸载重装. 查看 ...

  7. [LeetCode] Network Delay Time 网络延迟时间

    There are N network nodes, labelled 1 to N. Given times, a list of travel times as directed edges ti ...

  8. python字符串-内置方法列举

    所谓内置方法,就是凡是字符串都能用的方法,这个方法在创建字符串的类中,下面是总结: 首先,我们要学习一个获取帮助的内置函数 help(对象) ,对象可以是一个我们创建出来的,也可以是创建对象的那个类, ...

  9. 第一届“百度杯”信息安全攻防总决赛_Upload

    题目见i春秋ctf训练营 看到fast,就想抓个包看看,以前有道题是打开链接直接来了个跳转,当然这题不是 查看返回包,发现一个好东西 拿去base64解码看看 感觉给出的字符串能继续解码,果然解码后得 ...

  10. 【网络流】【BZOJ1221】【HNOI2001】软件开发

    原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1221 题意:你有3种方法进行对毛巾的处理,不同的处理方法有不同的cost,问你要如何规划才 ...