标签:integers digit Hopscotch int grid hop POJ include 3050
Hopscotch
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6761 | Accepted: 4354 |
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 lineOutput
* Line 1: The number of distinct integers that can be constructedSample 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.
题意:给一个5x5的矩阵,从矩阵的任意一个位置开始搜索6次,(允许方向为上下左右四个方向),问一可以产生多少个不同的序列
#include<iostream> #include<string.h> #include<string> #include<algorithm> #include<queue> #include<set> using namespace std; char a[10][10]; int dir[4][2]={{0,-1},{0,1},{1,0},{-1,0}}; set<string>p; string s; int check(int x,int y) { if(x>=0&&x<5&&y>=0&&y<5) return 1; else return 0; } void dfs(int x,int y,int n) { if(n>=6) { p.insert(s); return ; } for(int i=0;i<4;i++) { int dx,dy; dx=x+dir[i][0]; dy=y+dir[i][1]; if(check(dx,dy)==0) continue; s=s+a[dx][dy]; dfs(dx,dy,n+1); s.erase(n); } return ; } int main() { for(int i=0;i<5;i++) { for(int j=0;j<5;j++) cin>>a[i][j]; } for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { s.clear(); dfs(i,j,0); } } cout<<p.size()<<endl; // set<string>::iterator it; // for(it=p.begin();it!=p.end();it++) // { // cout<<*it<<endl; // } }
标签:integers,digit,Hopscotch,int,grid,hop,POJ,include,3050 来源: https://www.cnblogs.com/-citywall123/p/11295587.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。