codeforces 633C. Spy Syndrome 2 hash
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 把每一个小的串hash一下, 然后就可以在大的串里面找了, 具体看代码, 很清楚。
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
map <ll, string> mp;
ll dp[];
void print(int n) {
if(!n)
return ;
string tmp = mp[dp[n]];
print(n-tmp.size());
cout<<tmp<<" ";
}
int main()
{
int n, m;
string s, str;
cin>>n>>s>>m;
for(int i = ; i<m; i++) {
cin>>str;
int len = str.size();
ll tmp = ;
for(int j = ; j<len; j++) {
tmp = tmp*+tolower(str[j]);
}
mp[tmp] = str;
}
mem1(dp);
dp[] = ;
int len = s.size();
for(int i = ; i<len; i++) {
ll tmp = ;
for(int j = i; j>=; j--) {
tmp = tmp*+s[j];
if(dp[j]!=- && mp.count(tmp)) {
dp[i+] = tmp;
break;
}
}
}
int i = ;
print(len);
return ;
}
codeforces 633C. Spy Syndrome 2 hash的更多相关文章
- Codeforces 633C Spy Syndrome 2 | Trie树裸题
		Codeforces 633C Spy Syndrome 2 | Trie树裸题 一个由许多空格隔开的单词组成的字符串,进行了以下操作:把所有字符变成小写,把每个单词颠倒过来,然后去掉单词间的空格.已 ... 
- Codeforces 633C Spy Syndrome 2(DP + Trie树)
		题目大概说给一个加密的字符串,加密规则是把原文转化成小写字母,然后各个单词反转,最后去掉空格.现在给几个已知的单词,还原加密的字符串. 和UVa1401一个道理.. 用dp[i]表示加密字符前i个字符 ... 
- Codeforces 633C Spy Syndrome 2 【Trie树】+【DFS】
		<题目链接> 题目大意:给定一个只有小写字母组成的目标串和m个模式串(里面可能有大写字母),记目标串反过来后的串为S,让你从m个模式串中选出若干个组成S串(不区分大小写).输出任意一种方案 ... 
- [codeforces] 633C Spy Syndrome 2
		原题 Trie树+dp 首先,我们可以简单的想到一种dp方式,就是如果这一段可以匹配并且可以与前一段接上,那么更新dp[i]为当前字符串的编号,然后倒推就可以得到答案. 但是,显然我们不能O(m)比较 ... 
- CF#633C Spy Syndrome 2 DP+二分+hash
		Spy Syndrome 2 题意 现在对某个英文句子,进行加密: 把所有的字母变成小写字母 把所有的单词反过来 去掉单词之间的空格 比如:Kira is childish and he hates ... 
- 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 ... 
- Codeforce 633.C Spy Syndrome 2
		C. Spy Syndrome 2 time limit per test 2 seconds memory limit per test 256 megabytes input standard i ... 
随机推荐
- jquery设置文本框值 与获取文本框的值
			<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ... 
- node.js(五)字符串转换
			1.stringify函数的基本用法 stringify函数的作用就是序列化对象,也就是说将对象类型转换成一个字符串类型(默认的分割符("&")和分配符("=&q ... 
- 第二章SignalR所支持的平台
			第二章SignalR所支持的平台 SignalR支持各种服务器和客户端的配置.此外,每种传输方式都有自身的配置要求和限制:如果某种传输方式不被系统支持,SignalR优雅地将故障转移到其他类型的传输方 ... 
- css黑魔法
			多行文本溢出显示省略号(...)的方法 p { overflow : hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-li ... 
- UTL_FILE 的用法
			UTL_FILE 的用法 UTL_FILE 是用来进行文件IO处理的专用包,使用这外包的注意事项如下: 1. 生成的文件好象只能放置在DATABASE所在的服务器路径中. 2. 生成的文件如何DO ... 
- hibernate总结四
			HIbernate-查询语句 Hibernate Query Language (HQL) 是一个面向对象的查询语言,与Sql相似, 相对于sql对表和列的操作, HQL是对持久对象和他们的属性进行操 ... 
- 浅谈C中的指针和数组(二)
			原文转载地址:http://see.xidian.edu.cn/cpp/html/475.html 在原文的基础上增加自己的想法作为修改 很多初学者弄不清指针和数组到底有什么样的关系.我现在就告诉你: ... 
- const和非const函数重载
			成员函数后面加const,表示在该函数中不能对类的数据成员进行改变,比如下面的代码: #include <stdio.h> class A { private: mutable int a ... 
- jQuery treeview的简单用法
			最近的项目要用到treeview插件,刚好就自己整理一下这方面的资料. 1.文档树示例 最简单的一个例子就是文档树的实现.效果如下图所示. 在使用treeview之前,html文档中需要包含几个jqu ... 
- iMac Termanel命令まとめ
			1.mac环境下命令的使用ls -l -a 列出指定目录下文件 -l 显示文件的详细信息 -a 显示目录下所有文件(包括隐藏文件) -d ... 
