poj 3050 Hopscotch DFS+暴力搜索+set容器
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 2774 | Accepted: 1940 |
Description
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
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.
#include<cstdio>
#include<set>
#include<cstring>
using namespace std;
int a[7][7];
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
set<int> q;
int dfs(int step,int x,int y,int v)
{
if(step==6)
q.insert(v);
else
for(int i=0;i<=3;i++)
{
int kx=x+dx[i];
int ky=y+dy[i];
if(kx>=1&&kx<=5&&ky>=1&&ky<=5)
dfs(step+1,kx,ky,v*10+a[kx][ky]);
}
return 0;
}
int main()
{
for(int i=1;i<=5;i++)
for(int j=1;j<=5;j++)
scanf("%d",&a[i][j]);
for(int i=1;i<=5;i++)
for(int j=1;j<=5;j++)
dfs(1,i,j,a[i][j]);
printf("%d\n",q.size());
return 0;
}
poj 3050 Hopscotch DFS+暴力搜索+set容器的更多相关文章
- POJ 3050 Hopscotch 四方向搜索
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6761 Accepted: 4354 Descrip ...
- 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(dfs,stl)
用stack保存数字,set判重.dfs一遍就好.(或者编码成int,快排+unique #include<cstdio> #include<iostream> #includ ...
- POJ 3050 Hopscotch【DFS带回溯】
POJ 3050 题意: 1.5*5的方阵中,随意挑一格,记住这个格子的数字 2.可以上下左右走,走5次,每走一次记录下所走格子的数字 3.经过以上步骤,把所得6个数字连起来,形成一串数字.求共可以形 ...
- hdu 1427 速算24点 dfs暴力搜索
速算24点 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem De ...
- ACM: Gym 100935G Board Game - DFS暴力搜索
Board Game Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Gym 100 ...
- poj 2718 Smallest Difference(暴力搜索+STL+DFS)
Smallest Difference Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6493 Accepted: 17 ...
- POJ -3050 Hopscotch
http://poj.org/problem?id=3050 给定一个5×5矩阵,问选6个数的不同排列总数是多少! 二维的搜索,注意要判重,数据量很小,直接用map就好. #include<cs ...
- POJ 3050 Hopscotch 水~
http://poj.org/problem?id=3050 题目大意: 在一个5*5的格子中走,每一个格子有个数值,每次能够往上下左右走一格,问走了5次后得到的6个数的序列一共同拥有多少种?(一開始 ...
随机推荐
- Replication-Manager
MYSQL5.7下搭建Replication-Manager 环境说明 在主机1,主机2,主机3上安装MySQL服务端和客户端. 主机1 主机2 主机3 操作系统 CentOS7.4 CentOS7. ...
- 怎样解决在执行 vue init 时提示 "vue : 无法加载文件" 的问题?
注意, 以下操作需要 以管理员身份 在 PowerShell 中进行, 不能是 CMD / Git Bash 等. 1. 以 管理员身份 运行 PowerShell 2. 执行 get-Executi ...
- STL-set 容器以及迭代器的简单理解
先说下set的基本操作和时间复杂度 begin() ,返回set容器的第一个元素 end() ,返回set容器的最后一个元素 clear() ,删除set容器中的所有的元素 em ...
- 8.bash编辑命令行
8.编辑命令行本章介绍 GNU 命令行编辑界面的基本功能.命令行编辑是 Readline 库提供的:这个库被几个不同的程序共用,Bash 是其中一个.使用交互式的 shell 时,默认已经打开了命令行 ...
- vue入门:(模板语法与指令)
vuejs使用及HTML的模板语法,可以实现声明式将DOM绑定至底层VUE实例的数据.通过模板语法将数据渲染进DOM的系统,结合响应系统,在应用状态改变时,Vue能够计算出重新渲染组件的最小代价并应用 ...
- 搭建vue.js 的npm脚手架
1.在cmd中,找到nodeJs安装的路径下,运行 vue -V,查看当前vue版本,如下图所示,表明已经安装过了. 2.没有安装,进行安装.在cmd中,找到nodeJs安装的路径下,运命令行 npm ...
- app hellocharts 柱状图
app里有个告警数量的柱状图,有点小问题,y轴竟然不是整数 这个改起来到是简单 Axis yAxis = new Axis().setHasLines(true).setTextColor(Color ...
- 阿里P8架构师谈:MySQL慢查询优化、索引优化、以及表等优化总结
更多内容:https://www.toutiao.com/i6599796228886626829/?tt_from=weixin&utm_campaign=client_share& ...
- 使用dockerfile构建nginx镜像 转
docker构建镜像的方法: commit.dockerfile 1.使用commit来构建镜像: commit是基于原有镜像基础上构建的镜像,使用此方法构建镜像的目的:保存镜像里的一些配置信 ...
- Delphi DLL文件的静态调用