HDU 5202 Rikka with string (水DFS)
来源:互联网 发布:计算一组数据的标准差 编辑:程序博客网 时间:2024/05/18 00:26
Rikka with string
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 624 Accepted Submission(s): 243
Problem DescriptionAs we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:
One day, Yuta got a string which contains n letters but Rikka lost it in accident. Now they want to recover the string. Yuta remembers that the string only contains lowercase letters and it is not a palindrome string. Unfortunately he cannot remember some letters. Can you help him recover the string?
It is too difficult for Rikka. Can you help her?
One day, Yuta got a string which contains n letters but Rikka lost it in accident. Now they want to recover the string. Yuta remembers that the string only contains lowercase letters and it is not a palindrome string. Unfortunately he cannot remember some letters. Can you help him recover the string?
It is too difficult for Rikka. Can you help her?
This problem has multi test cases (no more than20 ). For each test case, The first line contains a number n(1≤n≤1000) . The next line contains an n-length string which only contains lowercase letters and ‘?’ – the place which Yuta is not sure.
For each test cases print a n-length string – the string you come up with. In the case where more than one string exists, print the lexicographically first one. In the case where no such string exists, output “QwQ”.
5a?bb?3aaa
aabbaQwQ
BestCoder Round #37 ($)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5202
题目大意:问号处填字母要求字典序最小且非回文
题目分析:遇到问号搜一下,字母从a到z枚举,搜完一组判断是否是回文,不是就退出,否则回溯继续搜
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5202
题目大意:问号处填字母要求字典序最小且非回文
题目分析:遇到问号搜一下,字母从a到z枚举,搜完一组判断是否是回文,不是就退出,否则回溯继续搜
#include <cstdio>#include <cstring>char s[1005];int n;bool flag;bool ok(){ for(int i = 0; i < n / 2; i++) if(s[i] != s[n - i - 1]) return true; return false;}void DFS(int pos){ if(pos == n) { if(ok()) flag = true; return; } if(s[pos] != '?') { DFS(pos + 1); if(flag) return; } else { for(char j = 'a'; j <= 'z'; j++) { s[pos] = j; DFS(pos + 1); if(flag) return; s[pos] = '?'; } } return;}int main(){ while(scanf("%d", &n) != EOF) { flag = false; scanf("%s", s); DFS(0); if(flag) printf("%s\n", s); else printf("QwQ\n"); }}
0 0
- HDU 5202 Rikka with string (水DFS)
- HDU - 5202 - Rikka with string (DFS)
- HDU-5202-Rikka with string(DFS + WrongAnswer)
- hdu 5202 Rikka with string
- HDU 5202 Rikka with string
- HDU 5202 Rikka with string
- hdu 5202 Rikka with string
- hdu 5202 Rikka with string
- HDU 5202 Rikka with string
- hdu 5202 Rikka with string
- Rikka with String HDU
- HDU - 5202 Rikka with string 贪心
- hdu 5202 Rikka with string(模拟)
- hdu 5423 Rikka with Tree DFS
- hdu 5423 Rikka with Tree(dfs)
- HDU 5423 Rikka with Tree(DFS)
- BestCoder #37 Rikka with string (hdu 5205)
- Rikka with string(较难DFS+回文判断)
- eXtremeDB connection pool
- 4、spss做多元线性回归
- java中switch() case用法和效率
- 链表各类操作详解
- C++面试笔试经典题集
- HDU 5202 Rikka with string (水DFS)
- 信号量的PV操作
- AsyncTask引发的问题
- 栈的顺序存储结构(数组)
- myeclipse安装、优化与插件安装
- 单线程实例区别Thread和Runnable方法
- AngularJS入门案例
- JSONObject与JSONArray的使用-解析Json
- 【整理】LINUX下使用CMAKE安装MYSQL