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. jq插件和jq

    封装一个jq (function(win) { var jQuery = function(selecter) { this.version = '1.0.1'; //版本号 this.selecte ...

  2. centos7创建ssh公钥

    步骤1:使用ssh-keygen命令创建公钥和私钥 [root@model /]# [root@model /]# ssh-keygen -t rsa -P '' Generating public/ ...

  3. 0105 springMVC开发基础

    背景 已经明确了MVC的思想和SpringMVC的基本流程,下面就都具体的mvc开发细节知识了. @RequestMapping springMVC核心流程中,启动阶段会把注解@RequeestMap ...

  4. CentOS7安装Jenkins与配置

    安装 将Jenkins存储库添加到yum repos,并从此安装Jenkins. sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenki ...

  5. POJ 3077 : Rounders

    Rounders Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7827 Accepted: 5062 Description ...

  6. 3D打印技术的火爆,真的会让传统模具行业没落吗?

    当一种新生事物出现时,人们除了赞美它带来的新畅想外,往往还会对"旧事物"贬低几分--各种淘汰观点总是不绝于耳.但可惜的是,新生事物取代旧事物的事儿并不会必然发生.比如,直到现在广播 ...

  7. 从0到1完成微信小程序开发(2)

    一,小程序的文件结构 小程序包含一个描述程序的app和多个描述各自页面的page 一个小程序主体部分由三个文件组成,必须放在项目的根目录,如下: 一个小程序页面由四个文件组成,分别是: 下面是一个单页 ...

  8. Python 爬虫是什么

    作为程序员,相信大家对“爬虫”这个词并不陌生,身边常常会有人提这个词,在不了解它的人眼中,会觉得这个技术很高端很神秘.不用着急,我们的爬虫系列就是带你去揭开它的神秘面纱,探寻它真实的面目. ! 爬虫是 ...

  9. 八十四、SAP中的ALV创建之三,创建ALV表格

    一.销售表是2个表,一个抬头表,一个是销售内容表,数据库查询语句如下, 二.我们添加相关LAYOUT的格式控制如下 三.需要报每个字段都用相应的LAYOUT控制一下 四.点击模式,在模式里面,添加RE ...

  10. web前端知识点

    一.CSS问题 1.flex布局 display:flex; 在父元素设置,子元素受弹性盒影响,默认排成一行,如果超出一行,按比例压缩 flex:1; 子元素设置,设置子元素如何分配父元素的空间,fl ...