Hopscotch
来源:互联网 发布:淘宝大c香港站是正品吗 编辑:程序博客网 时间:2024/05/17 07:39
题意大概为:从输入的5*5的网格的任意位置出发,移动5步得到一个六位数,判断能生成多少个不同的六位数。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int g[10][10];int ans=1,sum;int x[4]={0,0,1,-1};int y[4]={1,-1,0,0};int nums[6]={1,10,100,1000,10000,100000};int num[1000005];//存生成的不同的六位数int cmp()//判断当前生成的六位数sum是否与之前生成的六位数有重复{ for(int i=1;i<ans;i++) { if(sum==num[i]) { return -1; } } return 0;}void dfs(int i,int j,int deep){ if(deep==5)//深度为5的时候 { if(cmp()==0)//如果没有重复将sum存入num数组,ans增加 { num[ans++]=sum; } return ; } for(int k=0;k<4;k++) { int ii=i+x[k]; int jj=j+y[k]; if(ii>=0&&ii<5&&jj>=0&&jj<5)//不超范围就继续深搜 { sum+=g[ii][jj]*nums[deep+1]; dfs(ii,jj,deep+1); sum-=g[ii][jj]*nums[deep+1]; } }}int main(){ for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { cin>>g[i][j]; } } memset(num,0,sizeof(num)); for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { sum=0; sum+=g[i][j]*nums[0]; dfs(i,j,0); } } cout<<ans-1<<endl; return 0;}
0 0
- Hopscotch
- Hopscotch
- Hopscotch
- * Hopscotch
- Hopscotch
- Hopscotch
- Hopscotch
- POJ3050 Hopscotch
- POJ3258River Hopscotch
- POJ3050--Hopscotch
- River Hopscotch
- POJ3050-Hopscotch
- River Hopscotch
- Hopscotch POJ3050
- River Hopscotch
- River Hopscotch
- poj3258River Hopscotch
- POJ3050 Hopscotch
- 世界杯Again!——并查集 and STL(其实完全可以不用并查集)
- 《TCP/IP详解卷2:实现》笔记--IP选项处理
- POJ 3614 Sunscreen 贪心 优先队列
- 图的概念和关于图的几个算法
- Android内核sysfs中switch类使用实例
- Hopscotch
- JAVA处理日期时间常用方法:强大的calendar类
- va_list
- sql基础之DDL(Data Definition Languages)
- eclipse 启动后,闪退
- linux 常用命令
- poj 3928 Ping pong(数据结构:树状数组)
- HDU 4502 简单DP
- 提高Android应用手写流畅度(基础篇)