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实现的水平和垂直居中的div窗口
在建立网页布局的时候,我们经常会面临一个问题,就是让一个div实现水平和垂直居中,虽然好几种方式实现,但是今天介绍时我最喜欢的方法,通过css和jQuery实现. 1.通过css实现水平居中: 复 ...
- html系列教程--元素
HTML 元素语法 HTML 元素以开始标签起始 HTML 元素以结束标签终止 元素的内容是开始标签与结束标签之间的内容 某些 HTML 元素具有空内容(empty content) 空元素在开始标签 ...
- Android入门——UI(9)
SwipRefreshLayout下拉刷新控件 <?xml version="1.0" encoding="utf-8"?> <android ...
- 微信sdk (1)
<?php /** * wechat php test */ //define your token define("TOKEN", "weixin"); ...
- 如何在 webApi 当中接收 Gzip 压缩或者加密后的 请求消息内容!
今天在上班的时候遇到个问题,移动端要求我们用GZIP加密.当时一想着多简单,但是在做的时候发现个问题. 就是移动端Post到 服务端的数据也是经过 Gzip的,并不是单一的像网站那样只针对网页进行 压 ...
- 接收Dialog的值
System.Windows.Forms.DialogResult result = MessageBoxEx.Show("保存成功", Language.String.Hint, ...
- VBA基础知识———常用语句
语句一:if判断语句 Sub 判断1() '单条件判断 If Range("a1").Value > 0 Then Range("b1") = " ...
- 怎样在超级终端和PC之间通过串口传输文件
Windows环境下,通过SecureCRT软件,用串口向ARM开发板发送文件: 输入命令 rz,可以看到如下图所示: 选择路径点击上传即可. 如果是想从Arm开发板中把文件Down下来,则可以按照下 ...
- Windows 7/Vista 开机自动登录
“Win”+“R”打开命令窗口,输入"control userpasswords2"(不包括引号),或者 “rundll32 netplwiz.dll,UsersRunDll” 回 ...
- python 32位、64位确定
1.python 进入交互式命令行,如下: 2.执行以下命令: import struct;print struct.calcsize("P") * 8