POJ 3050:Hopscotch
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 2506 | Accepted: 1784 |
Description
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
Output
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
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的更多相关文章
- 【POJ - 3050】Hopscotch (dfs+回溯)
-->Hopscotch 这接写中文了 Descriptions: 奶牛们以一种独特的方式玩孩子们的跳房子游戏. 奶牛们创造了一个5x5的格子 他们熟练地跳上其中的一个格子,可以前后左右地跳(不 ...
- POJ 3050 Hopscotch【DFS带回溯】
POJ 3050 题意: 1.5*5的方阵中,随意挑一格,记住这个格子的数字 2.可以上下左右走,走5次,每走一次记录下所走格子的数字 3.经过以上步骤,把所得6个数字连起来,形成一串数字.求共可以形 ...
- 二分搜索 POJ 3258 River Hopscotch
题目传送门 /* 二分:搜索距离,判断时距离小于d的石头拿掉 */ #include <cstdio> #include <algorithm> #include <cs ...
- 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 ...
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
- POJ 3050 Hopscotch 水~
http://poj.org/problem?id=3050 题目大意: 在一个5*5的格子中走,每一个格子有个数值,每次能够往上下左右走一格,问走了5次后得到的6个数的序列一共同拥有多少种?(一開始 ...
- POJ -3050 Hopscotch
http://poj.org/problem?id=3050 给定一个5×5矩阵,问选6个数的不同排列总数是多少! 二维的搜索,注意要判重,数据量很小,直接用map就好. #include<cs ...
- 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 ...
- POJ 3050 Hopscotch 四方向搜索
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6761 Accepted: 4354 Descrip ...
随机推荐
- Linux系统-----包管理器的演变
每个电脑设备都使用某种形式的软件来执行其预定任务.在软件开发的早期,对产品进行了严格的bug和其他缺陷测试.在过去的十多年里,软件通过互联网发布,目的是通过应用新版本的软件来修复任何错误.在某些情况下 ...
- centos下离线安装zip和unzip
首先如果你的centos可以联网,那可以不用看了,直接yum install -y zip unzip就行,非常的痛快! 如果不能联网,像我一样,只能用vpn连上去,做了点限制.那就非常烦了,yum了 ...
- 用BusyBox制作Linux最小系统
1.下载busybox-1.30.1 地址:https://busybox.net/downloads/busybox-1.30.1.tar.bz2 2.解压:tar xvf busybox-1.30 ...
- 1.HDFS分布式文件系统
HDFS概述及设计目标 如果让我们自己设计一个分布式文件存储系统,怎么做? HDFS设计目标 非常巨大的分布式文件系统 运行在普通廉价的硬件上 易扩展,为用户提供性能不错的文件存储系统 HDFS架构 ...
- login SMTP send mail error : Unable to read data from the transport connection: net_io_connectionclosed
client.Credentials = new NetworkCredential(sSMTPuser, sSMTPpass); client.Credentials = new NetworkCr ...
- 05 MySQL数据类型的选择与使用
数据类型的选择 1.CHAR与VARCHAR 存储/检索的方式不同. CHAR是固定长度,而VARCHAR是可变长度 非SQLMode下,超 ...
- P1002 写出这个数(Basic Level)
转跳点:
- redis : Can't save in background: fork: Cannot allocate memory
redis : Can't save in background: fork: Cannot allocate memory JAVA程序报错信息: MISCONF Redis is configur ...
- <老古董>线性支持向量机中的硬间隔(hard margin)和软间隔(soft margin)是什么
_________________________________________________________________________________________________ Th ...
- 【SQL必知必会笔记(2)】检索数据、排序检索数据
上个笔记中介绍了一些关于数据库.SQL的基础知识,并且创建我们后续练习所需的数据库.表以及表之间的关系,从本文开始进入我们的正题:SQL语句的练习. 文章目录 1.检索数据(SELECT语句) 1.1 ...