Hopscotch
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2506   Accepted: 1784

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.

这个题题意是给一个5*5的矩阵,你可以从任意一个起点走5步,每一步可以上下左右那么走,记录你走过的路径,即你脚下的位置的value,输出不同的路径个数。

自己想输出不同的值,用的vector。。。结果一看其他人用的set比我的方便好多,而且直接insert啊,set自动去重啊。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#pragma warning(disable:4996)
using namespace std; int value[7][7];
vector<int>road; void dfs(int i,int j,int step,int test)
{
if(step==6)
{
test = test*10+value[i][j];
road.push_back(test);
return;
}
test = test*10+value[i][j]; if(i>1)
{
dfs(i-1,j,step+1,test);
}
if(j>1)
{
dfs(i,j-1,step+1,test);
}
if(i<5)
{
dfs(i+1,j,step+1,test);
}
if(j<5)
{
dfs(i,j+1,step+1,test);
}
} int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
cin>>value[i][j];
}
}
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
dfs(i,j,1,0);
}
}
sort(road.begin(), road.end());
vector<int>::iterator iter =unique(road.begin(),road.end());
road.erase(iter,road.end()); cout<<road.size()<<endl;
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 3050:Hopscotch的更多相关文章

  1. 【POJ - 3050】Hopscotch (dfs+回溯)

    -->Hopscotch 这接写中文了 Descriptions: 奶牛们以一种独特的方式玩孩子们的跳房子游戏. 奶牛们创造了一个5x5的格子 他们熟练地跳上其中的一个格子,可以前后左右地跳(不 ...

  2. POJ 3050 Hopscotch【DFS带回溯】

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

  3. 二分搜索 POJ 3258 River Hopscotch

    题目传送门 /* 二分:搜索距离,判断时距离小于d的石头拿掉 */ #include <cstdio> #include <algorithm> #include <cs ...

  4. POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)

    http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...

  5. POJ 3252:Round Numbers

    POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...

  6. POJ 3050 Hopscotch 水~

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

  7. POJ -3050 Hopscotch

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

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

  9. POJ 3050 Hopscotch 四方向搜索

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

随机推荐

  1. 【Winform】ProgressBar

    var progressBar1 = new System.Windows.Forms.ProgressBar(); ; progressBar1.Maximum = ; progressBar1.V ...

  2. #$d#$a什么意思

    #$d#$a什么意思 qjh.693111级分类:外语被浏览37次2013.05.12   满意答案 vgrwi 采纳率:50%12级 2013.05.13 回车换行 换成十进制就是 #13#10

  3. R分析实现对招聘网站薪资预测分析

    1.首先确定数据分析目标——薪酬受哪些因素影响 确定变量: 因变量:薪资 自变量:(定性)-- 公司类别.公司规模.地区.行业类别.学历要求.软件要求. (定量)-- 经验要求(数值型) 分析目标:建 ...

  4. 查看Python安装目录 -- 一个命令

    pip --version

  5. JS:利用for循环进行数组去重

    <script> var a = [1, 3, 2, 4, 5, 3, 2, 1, 4, 6, 7, 7, 6, 6]; //示例数组    var b = []; for(var i = ...

  6. TS文件极简合并

    TS文件是可以直接通过二进制拷贝连接的方式进行合并的,一般采用如下的命令行参数:copy /b 1.ts+2.ts+3.ts new.ts 这个例子就是将1.ts.2.ts.3.ts三个文件按顺序连接 ...

  7. Ubuntu18.04可执行文件运行提示No such file or directory

    参考原文见 https://blog.csdn.net/sun927/article/details/46593129? 最近我也遇到一个类似问题,同一个工具在Ubuntu16.04里面运行是好的,但 ...

  8. 1 —— js 语法回顾 —— 数据类型。流程控制。数组

    一,数据类型 字符串 . 数值 .布尔. null . undefined . 对象  ( 数组 . 函数 function(){} . object) undefined 出现的情景 :  (1)变 ...

  9. cf 500 D. New Year Santa Network

    直接按边分,2个点在边的一边,1个在另一边,组合出来就是这个边对答案的贡献,权值换了就再重新算个数而已. #include <bits/stdc++.h> #define LL long ...

  10. 五十八、SAP中常用预定义数据类型

    一.SAP中常用预定义数据类型 注意事项如下: 1.默认的定义数据类型是CHAR. 2.取值的时候C型默认从左取,N型从右取,超过定义长度则截断. 3.C类型,可以赋值数值,也可以赋值字符,还可以混合 ...