Rikka with string

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1411    Accepted Submission(s): 502

Problem Description
As
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?

 
Input
This problem has multi test cases (no more than 20). 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.
 
Output
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”.
 
Sample Input
5
a?bb?
3
aaa
 
Sample Output
aabba
QwQ
 
暴力:直接枚举?处的答案,得到的第一个必定字典序最小
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;
char str[],res[];
int n;
bool flag;
bool judge(char *str){
int len = strlen(str);
for(int i=,j=len-;i<=j;i++,j--){
if(str[i]!=str[j]) return true;
}
return false;
}
void dfs(int step){
if(flag) return;
if(step==n) {
if(judge(str)){
flag = true;
strcpy(res,str);
}
return;
}
if(str[step]=='?'){
for(int i='a';i<='z';i++){
str[step]=i;
dfs(step+);
str[step]='?';
}
}else{
dfs(step+);
}
return;
}
int main(){ while(scanf("%d",&n)!=EOF){
flag= false;
scanf("%s",str);
dfs();
if(flag) printf("%s\n",res);
else printf("QwQ\n");
}
}

hdu 5202(DFS)的更多相关文章

  1. HDU 5143 DFS

    分别给出1,2,3,4   a, b, c,d个 问能否组成数个长度不小于3的等差数列. 首先数量存在大于3的可以直接拿掉,那么可以先判是否都是0或大于3的 然后直接DFS就行了,但是还是要注意先判合 ...

  2. Snacks HDU 5692 dfs序列+线段树

    Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...

  3. HDU 5877 dfs+ 线段树(或+树状树组)

    1.HDU 5877  Weak Pair 2.总结:有多种做法,这里写了dfs+线段树(或+树状树组),还可用主席树或平衡树,但还不会这两个 3.思路:利用dfs遍历子节点,同时对于每个子节点au, ...

  4. hdu 4751(dfs染色)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4751 思路:构建新图,对于那些两点连双向边的,忽略,然后其余的都连双向边,于是在新图中,连边的点是能不 ...

  5. HDU 1045 (DFS搜索)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1045 题目大意:在不是X的地方放O,所有O在没有隔板情况下不能对视(横行和数列),问最多可以放多少个 ...

  6. HDU 1241 (DFS搜索+染色)

    题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=1241 题目大意:求一张地图里的连通块.注意可以斜着连通. 解题思路: 八个方向dfs一遍,一边df ...

  7. HDU 1010 (DFS搜索+奇偶剪枝)

    题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意:给定起点和终点,问刚好在t步时能否到达终点. 解题思路: 4个剪枝. ①dep&g ...

  8. hdu 1716(dfs)

    题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=1716     排列2   Problem Description Ray又对数字的列产生了兴趣:现 ...

  9. hdu 4705 dfs统计更新节点信息

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4705 #pragma comment(linker, "/STACK:16777216&qu ...

随机推荐

  1. Linux内核设计与实现第五周读书笔记

    第十八章 调试 18.1准备开始 需要的只是: 一个确定的bug.大部分bug通常都不是行为可靠而且定义明确的. 一个藏匿bug的内核版本. 相关的内核代码的知识和运气. 18.2内核中的bug 内核 ...

  2. bzoj3884: 上帝与集合的正确用法(数论)

    感觉是今天洛谷月赛T3的弱化版,会写洛谷T3之后这题一眼就会写了... 还是欧拉扩展定理 于是就在指数上递归%phi(p)+phi(p)直到1,则后面的指数就都没用了,这时候返回,边回溯边快速幂.因为 ...

  3. 解题:SDOI 2013 保护出题人

    题面 首先是愉快的推式子 $dp[i]=max(dp[i],\frac{sum[i]-sum[j-1]}{x[i]+(i-j)*d})(1<=j<=i<=n)$(考虑有一只僵尸正好走 ...

  4. form, table表示表格的时候有什么区别?

    http://zhidao.baidu.com/link?url=1DFrMJlzV_fHSyGmKEi77ki6g2IrjrMfRGwVYNHL5Y8iJC9Diu2BoMGEiB3wbnkTCHm ...

  5. Codeforces 830B - Cards Sorting 树状数组

    B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  6. McNemar test麦克尼马尔检验

    sklearn实战-乳腺癌细胞数据挖掘(博主亲自录视频) https://study.163.com/course/introduction.htm?courseId=1005269003&u ...

  7. C++ string的那些坑

    1. size_type find_first_of( const basic_string &str, size_type index = 0 ); 查找在字符串中第一个与str中的某个字符 ...

  8. 【整理】explain、type、extra用法和结果的含义

    EXPLAIN列详情 详细解读:https://www.cnblogs.com/yycc/p/7338894.html explain显示了mysql如何使用索引来处理select语句以及连接表.可以 ...

  9. 816B. Karen and Coffee 前缀和思维 或 线段树

    LINK 题意:给出n个[l,r],q个询问a,b,问被包含于[a,b]且这样的区间数大于k个的方案数有多少 思路:预处理所有的区间,对于一个区间我们标记其(左边界)++,(右边界+1)--这样就能通 ...

  10. LintCode 397: Longest Increasing Continuous Subsequence

    LintCode 397: Longest Increasing Continuous Subsequence 题目描述 给定一个整数数组(下标从0到n - 1,n表示整个数组的规模),请找出该数组中 ...