1262 - Password (暴力枚举)
来源:互联网 发布:淘宝商品详情页多少钱 编辑:程序博客网 时间:2024/06/01 09:08
该题应该是用数学的组合知识做,不过因为密码格子很小,暴力枚举很快而且不容易做错 。
需要注意一点,因为每一列中可能有重复的字母,所以会出现重复的密码,因此要在dfs之前排序去重。
细节参见代码:
#include<bits/stdc++.h>using namespace std;int T,k,n,m,cnt;char s1[10][10],s2[10][10],ans[10],len[10],a1[10][10],a2[10][10];bool dfs(int cur) { if(cur == 5) { cnt++; ans[cur] = '\0'; if(cnt == k) { printf("%s\n",ans); return true; } } for(int i=0;i<len[cur];i++) { bool ok = false; for(int j=0;j<6;j++) if(a2[cur][j] == a1[cur][i]) { ok = true; break; } if(ok) { ans[cur] = a1[cur][i]; if(dfs(cur+1)) return true; } } return false;}int main() { scanf("%d",&T); while(T--) { scanf("%d",&k); for(int i=0;i<6;i++) scanf("%s",s1[i]); for(int i=0;i<6;i++) scanf("%s",s2[i]); for(int i=0;i<5;i++) { for(int j=0;j<6;j++) { a1[i][j] = s1[j][i]; a2[i][j] = s2[j][i]; } } for(int i=0;i<5;i++) { sort(a1[i],a1[i]+6); len[i] = unique(a1[i],a1[i]+6) - a1[i] ; } cnt = 0; if(!dfs(0)) printf("NO\n"); } return 0;}
1 0
- 1262 - Password (暴力枚举)
- UVA 1262 Password 暴力枚举
- UVa1262 - Password(暴力枚举)
- HLJUOJ1122(暴力枚举)
- HDU2566(暴力枚举)
- hdu1015(暴力枚举。。。。)
- Friends (暴力枚举)
- Safecracker(枚举暴力)
- 暴力枚举(刷题)
- “暴力”枚举(穷举)
- C. Dasha and Password(模拟,暴力)
- Dasha and Password (暴力+贪心)
- hdu 4968(暴力枚举)
- 炸弹人(暴力枚举)
- poj 3671(暴力 枚举)
- Friend-Graph(暴力枚举)
- 完美数列(暴力枚举)
- 暴力枚举
- hdu1255 覆盖的面积
- linux下 Apache 配置虚拟主机三种方式
- 进程同步与互斥:POSIX有名信号量
- hdoj 2680 Choose the best route
- postgresql for linux
- 1262 - Password (暴力枚举)
- 浅析Mysql Join语法以及性能优化
- iOS 传值总结
- Prim算法 之 Java详解
- 这是我的第一篇博客
- hdu 1269 迷宫城堡(搜索tarjin)
- 如何在pdf上修改
- Spring基于注解配置Bean
- 遍历Map的四种方法