UVA
来源:互联网 发布:人肉俄罗斯转盘 知乎 编辑:程序博客网 时间:2024/06/06 03:40
题目链接:https://vjudge.net/problem/UVA-1262
题目大意:5列中每列取出一个字母,这个字母在两张表中的同一列都出现过,求组成的字符串第K大的字符串。
解题思路:暴力枚举,坑点就是每一列的字母可能重复
AC代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;char gt[2][6][5], ch[5][6], ansch[5];int chtot[5], ranking, k;bool vis[5][300];void Dfs(int t){ if (t == 5) { ranking++; if (ranking == k) { for (int i = 0;i < 5;i++) printf("%c", ansch[i]); puts(""); } return; } for (int i = 0;i < chtot[t];i++) { if (ranking != k) { ansch[t] = ch[t][i]; Dfs(t + 1); } }}int main(){ int t;scanf("%d", &t); while (t--) { scanf("%d", &k); for (int i = 0;i < 2;i++) for (int j = 0;j < 6;j++) for (int l = 0;l < 5;l++) scanf(" %c", >[i][j][l]); memset(vis, 0, sizeof(vis)); memset(chtot, 0, sizeof(chtot)); ranking = 0; for (int i = 0;i < 6;i++) for (int j = 0;j < 5;j++) vis[j][gt[0][i][j] - 'A'] = 1; for (int i = 0;i < 6;i++) for (int j = 0;j < 5;j++) if (vis[j][gt[1][i][j] - 'A']) ch[j][chtot[j]++] = gt[1][i][j]; for (int i = 0;i < 5;i++) { sort(ch[i], ch[i] + chtot[i]); chtot[i] = unique(ch[i], ch[i] + chtot[i]) - ch[i]; } int ans = 1; for (int i = 0;i < 5;i++) ans *= chtot[i]; if (ans < k) puts("NO"); else Dfs(0); } return 0;}
阅读全文
0 0
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- C++ MD5
- 文章标题
- 数据结构 顺序查找和二分查找
- 软件工程(C编码实践篇)学习总结
- poj 1035 Spell checker
- UVA
- SD卡文件读写
- mysql字段text类型的使用
- 有关C++ 实现时extern 和const的问题
- poj 2231 Moo Volume
- 小程序合集1(素数、闰年、乘法表)
- centos 怎么用 基本知识
- pandas中利用get_dummies()进行独热编码(One-Hot encoding)
- DGHLDKFHLDFH