hdu 5202(DFS)
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
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?
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”.
a?bb?
3
aaa
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)的更多相关文章
- HDU 5143 DFS
分别给出1,2,3,4 a, b, c,d个 问能否组成数个长度不小于3的等差数列. 首先数量存在大于3的可以直接拿掉,那么可以先判是否都是0或大于3的 然后直接DFS就行了,但是还是要注意先判合 ...
- Snacks HDU 5692 dfs序列+线段树
Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...
- HDU 5877 dfs+ 线段树(或+树状树组)
1.HDU 5877 Weak Pair 2.总结:有多种做法,这里写了dfs+线段树(或+树状树组),还可用主席树或平衡树,但还不会这两个 3.思路:利用dfs遍历子节点,同时对于每个子节点au, ...
- hdu 4751(dfs染色)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4751 思路:构建新图,对于那些两点连双向边的,忽略,然后其余的都连双向边,于是在新图中,连边的点是能不 ...
- HDU 1045 (DFS搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1045 题目大意:在不是X的地方放O,所有O在没有隔板情况下不能对视(横行和数列),问最多可以放多少个 ...
- HDU 1241 (DFS搜索+染色)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 题目大意:求一张地图里的连通块.注意可以斜着连通. 解题思路: 八个方向dfs一遍,一边df ...
- HDU 1010 (DFS搜索+奇偶剪枝)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意:给定起点和终点,问刚好在t步时能否到达终点. 解题思路: 4个剪枝. ①dep&g ...
- hdu 1716(dfs)
题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=1716 排列2 Problem Description Ray又对数字的列产生了兴趣:现 ...
- hdu 4705 dfs统计更新节点信息
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4705 #pragma comment(linker, "/STACK:16777216&qu ...
随机推荐
- dorado重置按钮事件
// @Bind #btnReset.onClick!function(self, arg) { var subNo = view.get("#dsQueryCriteria"). ...
- UESTC--1267
原题链接:http://www.acm.uestc.edu.cn/problem.php?pid=1267 分析:此题麻烦之处在于要输出最小最长上升子序列,关键在于如何解决最小这个问题. 我的做法是从 ...
- HDU4003 树形DP
题意 :给一棵n个节点的树, 节点编号为1~n, 每条边都有一个花费值. 有k个机器人从S点出发, 问让机器人遍历所有边,最少花费值多少? 这题最难的地方应该就是如何定义状态了 定义dp ...
- Qt ------ stylesheet 样式
1.所有的窗口组件都可以用 setStyleSheet() 设置样式 2.使用样式,显示效果可以不受平台影响,比如保证window 7 和 linux 显示效果是一样的 QVariant 如果 sty ...
- 使用nginx+docker配置https负载均衡
了解Docker Docker是一个golang编写的开源轻量级的.可移植的.自给自足的容器,Docker主要应用在以下场景: web应用的自动化打包和发布: 自动化测试和持续集成.发布: 在服务型环 ...
- JS中encodeURI、encodeURIComponent、decodeURI、decodeURIComponent
js 对文字进行编码涉及2个函数:encodeURI,encodeURIComponent,相应2个解码函数:decodeURI,decodeURIComponent 1.用来编码和解码URI的 统一 ...
- Oracle把本地的dmp备份文件导入到本地的Oracle数据库中语句
----------------------------------------------------------------------------- 导入语法 imp usename/passw ...
- C11线程管理:互斥锁
1.概述 锁类型 c11提供了跨平台的线程同步手段,用来保护多线程同时访问的共享数据. std::mutex,最基本的 Mutex 类,独占的互斥量,不能递归使用. std::time_mutex,带 ...
- cin.getline()与getline()
C++中有两个getline函数, cin.getline()与getline() 这两个函数相似,但是 这两个函数分别定义在不同的头文件中. cin.getline()属于istream流,而 ...
- BestCoder Round92
题目链接:传送门 HDU 6015-6018 解题报告:传送门 HDU6015 Skip the Class Accepts: 678 Submissions: 1285 Time Limit: ...