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 ...
随机推荐
- 定时执行 Job【转】
Linux 中有 cron 程序定时执行任务,Kubernetes 的 CronJob 提供了类似的功能,可以定时执行 Job.CronJob 配置文件示例如下: ① batch/v2alpha1 是 ...
- 微软重制Windows 1.0系统:祖师爷出山了
Windows官方推特在7月1日发布了一条很有趣的动态,“向大家介绍全新的Windows 1.0,带MS-DOS.时钟等”.配发的视频回顾了从Windows 1.0/3.1到Windows 10期间, ...
- sftp 多用户安装与配置
sftp 是 Secure File Transfer Protocol 的缩写,安全文件传送协议.可以为传输文件提供一种安全的加密方法.SFTP 为 SSH 的一部分,由于这种传输方式使用了加密/解 ...
- Unbutu下装oracle
Ubuntu 16.04安装Oracle 11gR2入门教程图文详解 转自 https://www.linuxidc.com/Linux/2017-12/149797.htm 原文作 ...
- Linux netfliter 架构
netfliter 简介 netfilter是在Linux 2.4.X内核引入的一个子系统,它提供了一个抽象的.通用框架,这个框架提供了一整套的钩子函数的管理机制.包括钩子函数的原型定义,注册,注销等 ...
- 在excel表格里,为所有数字添上绿色小三角
在excel表格里,为所有数字添上绿色小三角的方法有4种: 1. 为一个单元格添加:直接在单元格里添加一个英文的逗号 2. 为一列数据添加:选中要添加绿色小三角的列,选择 数据-->分列--&g ...
- Android明密文切换
前言: 在我们的登录界面经常会遇到查看自己输入密码是否正确,就会用到明密文切换 正文: 我们先写出xml文件文件中的代码,不用过多解释 <EditText android:layout_widt ...
- UVA - 536 Tree Recovery (二叉树重建)
题意:已知先序中序,输出后序. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio& ...
- 开源DDD设计模式框架YMNNetCoreFrameWork第四篇-增加YMNSession,增加异常处理,增加策略授权
1.增加YMNSession,可以获取当前登录的用户信息 2.增加异常处理,不要使用过滤器,过滤器只能获取到mvc异常 3.增加策略授权,策略授权支持用户角色.用户名授权,初步实现 代码地址:http ...
- exec()函数问题
源代码: 在网上也搜索了答案 比较详细的答案是: <?php exec("lsof -i:80",$out,$status); 结果: var_dump($out); arr ...