hdu.5202.Rikka with string(贪心)
Rikka with string
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 581 Accepted Submission(s): 227
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?
a?bb?
3
aaa
QwQ
#include<stdio.h>
#include<string.h>
int cnt = ;
char st[ + ] ;
char rst [ + ] ;
int n , vis[ + ]; void rev (char s[ + ])
{
char tmp[ + ] ;
int k = , i ;
for (i = strlen (st) - ; i >= ; i-- , k ++) {
tmp[k] = st[i] ;
}
tmp[k] = '\0' ;
strcpy (s , tmp) ;
} int main ()
{
// freopen ("a.txt" , "r" , stdin ) ;
while (~ scanf ("%d" , &n)) {
getchar () ;
gets (st) ;
cnt = ;
for (int i = ; st[i] != '\0' ;i ++) {
if (st[i] == '?') {
vis[cnt ++] = i ;
st[i] = 'a' ;
}
}
int i ;
rev (rst) ;
if (strcmp (st , rst)== ) {
for (i = cnt - ; i >= ; i--) {
st[vis[i]] = 'b' ;
rev (rst) ;
if (strcmp (rst , st)!= ) {
break ;
}
st[vis[i]] = 'a' ;
}
if (i == - ) puts ("QwQ") ;
else puts (st) ;
}
else puts (st) ;
}
return ;
}
如果没有不是回文串的限制可以把所有的?都变成a,这样一定是字典序最小的。而现在有了回文串的限制,我们可以从小到大枚举最靠后的不在字符串正中心的问号选什么,其他的问号依然换成a,显然如果有解,这样一定可以得到字典序最小的解。注意特判没有问号以及问号在正中心的情况。
时间复杂度O(n)
hdu.5202.Rikka with string(贪心)的更多相关文章
- HDU 6086 Rikka with String
Rikka with String http://acm.hdu.edu.cn/showproblem.php?pid=6086 题意: 求一个长度为2L的,包含所给定的n的串,并且满足非对称. 分析 ...
- HDU 6086 Rikka with String AC自动机 + DP
Rikka with String Problem Description As we know, Rikka is poor at math. Yuta is worrying about this ...
- hdoj - 5202 Rikka with string (BestCoder Round #37 ($))
http://acm.hdu.edu.cn/showproblem.php?pid=5202 字符串处理的题,要细心. 给定一个只包含小写字母和问号的字符串,让我们还原出本来的字符串,把问号替换成任意 ...
- hdu 6086 -- Rikka with String(AC自动机 + 状压DP)
题目链接 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, s ...
- HDU 6086 Rikka with String ——(AC自动机 + DP)
这是一个AC自动机+dp的问题,在中间的串的处理可以枚举中断点来插入自动机内来实现,具体参见代码. 在这题上不止为何一直MLE,一直找不到结果(lyf相同写法的代码消耗内存较少),还好考虑到这题节点应 ...
- HDU 5831 Rikka with Parenthesis II(六花与括号II)
31 Rikka with Parenthesis II (六花与括号II) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- HDU 6093 - Rikka with Number | 2017 Multi-University Training Contest 5
JAVA+大数搞了一遍- - 不是很麻烦- - /* HDU 6093 - Rikka with Number [ 进制转换,康托展开,大数 ] | 2017 Multi-University Tra ...
- HDU 5842 Lweb and String(Lweb与字符串)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence
// 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...
随机推荐
- IE firefox 兼容性整理
1.尽量用jquery操作. 2.jquery取值时要用准确的方法,attr(), val(), text(), html(). 例如: <span value="a"> ...
- 如何添加win10命令提示符字体,美化显示效果
如图,win10命令提示符的字体真让人难受的要死,难道就不能改成好看一点的吗?笔者开始了停不下来的百度和Google 在查找了大量零碎或者过时的资料后,终于找到了一篇看起来还是很靠谱的文章: Quic ...
- js判断页面点击事件
<input type="submit" name="sb1" id="sb1" onclick="queryclick() ...
- 浅谈分治算法在OI中的应用
分治虽然是基本思想,但是OI中不会出裸分治让你一眼看出来,往往都是结合到找规律里面. 先来个简单的: 奇妙变换 (magic.pas/c/cpp) [问题描述] 为了奖励牛牛同学帮妈妈解决了大写中 ...
- [工具类]DataTable与泛型集合List互转
写在前面 工作中经常遇到datatable与list,对于datatable而言操作起来不太方便.所以有的时候还是非常希望通过泛型集合来进行操作的.所以这里就封装了一个扩展类.也方便使用. 类 方法中 ...
- jquery.validate.js常用扩展函数
$(function () { // 判断整数value是否等于0 jQuery.validator.addMethod("isIntEqZero", function (valu ...
- loaded the "XXXView" nib but the view outlet was not set 解决方案
'-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "XXXView" nib but the view o ...
- Missing message for key "err1" in bundle "(default bundle)" for locale zh_CN
这个问题是: 你的使用了ApplicationResources_zh_CN.properties文件没有找到. 1.是struts-config.xml中的<message-resources ...
- Spring控制Hibernate的缓存机制ehcache
首先在spring.xml中进入bean <prop key="hibernate.cache.use_second_level_cache">true</pro ...
- 【kAri OJ604】圣哲的树
时间限制 1000 ms 内存限制 65536 KB 题目描述 果园大咖圣哲有12个棵树,其中有且仅有一个是有病的,有病的树比真的或轻或重,给出3次天平测量重量的结果,每次告知左侧和右侧的树各有哪几个 ...