Codeforce 633.C Spy Syndrome 2
2 seconds
256 megabytes
standard input
standard output
After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique.
For a given sentence, the cipher is processed as:
- Convert all letters of the sentence to lowercase.
- Reverse each of the words of the sentence individually.
- Remove all the spaces in the sentence.
For example, when this cipher is applied to the sentence
Kira is childish and he hates losing
the resulting string is
ariksihsidlihcdnaehsetahgnisol
Now Yash is given some ciphered string and a list of words. Help him to find out any original sentence composed using only words from the list. Note, that any of the given words could be used in the sentence multiple times.
The first line of the input contains a single integer n (1 ≤ n ≤ 10 000) — the length of the ciphered text. The second line consists of nlowercase English letters — the ciphered text t.
The third line contains a single integer m (1 ≤ m ≤ 100 000) — the number of words which will be considered while deciphering the text. Each of the next m lines contains a non-empty word wi (|wi| ≤ 1 000) consisting of uppercase and lowercase English letters only. It's guaranteed that the total length of all words doesn't exceed 1 000 000.
Print one line — the original sentence. It is guaranteed that at least one solution exists. If there are multiple solutions, you may output any of those.
30
ariksihsidlihcdnaehsetahgnisol
10
Kira
hates
is
he
losing
death
childish
L
and
Note
Kira is childish and he hates losing
12
iherehtolleh
5
HI
Ho
there
HeLLo
hello
HI there HeLLo
In sample case 2 there may be multiple accepted outputs, "HI there HeLLo" and "HI there hello" you may output any of them.
题目大意:将一个字符串加密的规则:先将所有字母变成小写字母,再将每个单词翻转,拼接在一起.现在给出可能用到的单词,还原字符串.
分析:既然题干中说所有的单词都翻转过来了,那么就把它给出的单词全部翻转过来.之后就有点像是在一个字典中查询单词有没有出现过这种操作,利用trie.因为n不大,在匹配加密串的时候可以用搜索:固定起点,枚举终点,每次看在trie中能不能找到结尾标记以及能不能走下去.翻转操作可以变成倒着插入trie.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n, m, tot = , cnt, ans[], len[];
char s[][], s2[]; struct node
{
int tr[];
int id;
}e[]; void insert(char *ss, int x)
{
int len = strlen(ss);
int u = ;
for (int i = len - ; i >= ; i--)
{
char ch = ss[i];
if (ch < 'a' || ch > 'z')
ch += 'a' - 'A';
int p = ch - 'a';
if (!e[u].tr[p])
e[u].tr[p] = ++tot;
u = e[u].tr[p];
}
e[u].id = x;
} void solve(int dep)
{
if (dep == n + )
{
for (int i = ; i < cnt; i++)
cout << s[ans[i]] << " ";
cout << s[ans[cnt]] << endl;
exit();
}
int u = ,i;
for (i = dep; i <= n; i++)
{
int p = s2[i] - 'a';
if (!e[u].tr[p])
break;
u = e[u].tr[p];
if (e[u].id)
{
ans[++cnt] = e[u].id;
solve(dep + len[e[u].id]);
--cnt;
}
}
} int main()
{
scanf("%d", &n);
scanf("%s", s2 + );
scanf("%d", &m);
for (int i = ; i <= m; i++)
{
scanf("%s", s[i]);
len[i] = strlen(s[i]);
insert(s[i], i);
}
solve(); return ;
}
Codeforce 633.C Spy Syndrome 2的更多相关文章
- Codeforces 633 C Spy Syndrome 2 字典树
题意:还是比较好理解 分析:把每个单词反转,建字典树,然后暴力匹配加密串 注:然后我就是特别不理解,上面那种能过,而且时间很短,但是我想反之亦然啊 我一开始写的是,把加密串进行反转,然后单词正着建字典 ...
- Codeforce 633C. Spy Syndrome 2
C. Spy Syndrome 2 time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Manthan, Codefest 16 C. Spy Syndrome 2 字典树 + dp
C. Spy Syndrome 2 题目连接: http://www.codeforces.com/contest/633/problem/C Description After observing ...
- Manthan, Codefest 16 -C. Spy Syndrome 2
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- codeforces 633C. Spy Syndrome 2 hash
题目链接 C. Spy Syndrome 2 time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces 633C Spy Syndrome 2 | Trie树裸题
Codeforces 633C Spy Syndrome 2 | Trie树裸题 一个由许多空格隔开的单词组成的字符串,进行了以下操作:把所有字符变成小写,把每个单词颠倒过来,然后去掉单词间的空格.已 ...
- CF#633C Spy Syndrome 2 DP+二分+hash
Spy Syndrome 2 题意 现在对某个英文句子,进行加密: 把所有的字母变成小写字母 把所有的单词反过来 去掉单词之间的空格 比如:Kira is childish and he hates ...
- CF #Manthan, Codefest 16 C. Spy Syndrome 2 Trie
题目链接:http://codeforces.com/problemset/problem/633/C 大意就是给个字典和一个字符串,求一个用字典中的单词恰好构成字符串的匹配. 比赛的时候是用AC自动 ...
- CF633C:Spy Syndrome 2——题解
https://vjudge.net/problem/CodeForces-633C http://codeforces.com/problemset/problem/633/C 点击这里看巨佬题解 ...
随机推荐
- Tomcat源码学习(2)——启动过程分析
Tomcat启动过程分析 启动 tomcat 时,Windows下执行 startup.bat :Linux下执行 startup.sh 文件,实际上最后都是调用 org.apache.catalin ...
- [笔记] postgresql 流复制(streaming replication)
基本环境说明: os:FreeBSD 9.3 postgresql version: master:192.168.56.101 standby:192.168.56.102 安装过程略,基于pkg包 ...
- Alpha发布用户使用报告
此作业要求参见:[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2325] 组名:可以低头,但没必要 组长:付佳 组员:张俊余 李文涛 孙 ...
- AVL树 算法思想与代码实现
AVL树是高度平衡的二叉搜索树,按照二叉搜索树(Binary Search Tree)的性质,AVL首先要满足: 若它的左子树不为空,则左子树上所有结点的值均小于它的根结点的值: 若它的右子树不为空, ...
- 20172321 2018-2019《Java软件结构与数据结构》第三周学习总结
教材学习内容总结 第五章 5.1概述 队列是一种线性集合,其元素从一端加入,从另一端删除:队列的处理方式是先进先出(First in First out). 与栈的比较(LIFO) 栈是一端操作,先进 ...
- Alpha 冲刺(10/10)
队名 火箭少男100 组长博客 林燊大哥 作业博客 Alpha 冲鸭鸭鸭鸭鸭鸭鸭鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调各成员之间的工作 测试整体软件 展示GitHub当 ...
- maven项目org.springframework.web.context.ContextLoaderListener的异常和tomcat zipexception的异常
使用到spring的maven web项目,在运行servers时,报错找不到org.springframework.web.context.ContextLoaderListener,web.xml ...
- 如何防止app接口被别人调用
app开发的时候,如何保护app的接口呢? 用https是我想到的办法,但是不知道怎么实现,所以就考虑用token,虽然不是绝对有效,但是能防止一般的用户来攻击,高手非要攻击,只能报警了吧. toke ...
- js中call(),apply(),以及prototype的含义
最近段时间主要学习前端去了,然而所遇到的一些问题我觉得有必要去深究一下 prototype: 1 js中有三种表达方法 类方法,属性方法,原型方法 function People(name) { th ...
- JavaScript与OC的交互-WebViewJavascriptBridge
WebViewJavascriptBridge实现了在使用UIWebView时JS与ios 的Objective-C nativecode之间的互相调用, 支持的功能有消息发送.接收.消息处理器的注册 ...