Educational Codeforces Round 78 (Rated for Div. 2) A. Shuffle Hashing
链接:
https://codeforces.com/contest/1278/problem/A
题意:
Polycarp has built his own web service. Being a modern web service it includes login feature. And that always implies password security problems.
Polycarp decided to store the hash of the password, generated by the following algorithm:
take the password p, consisting of lowercase Latin letters, and shuffle the letters randomly in it to obtain p′ (p′ can still be equal to p);
generate two random strings, consisting of lowercase Latin letters, s1 and s2 (any of these strings can be empty);
the resulting hash h=s1+p′+s2, where addition is string concatenation.
For example, let the password p= "abacaba". Then p′ can be equal to "aabcaab". Random strings s1= "zyx" and s2= "kjh". Then h= "zyxaabcaabkjh".
Note that no letters could be deleted or added to p to obtain p′, only the order could be changed.
Now Polycarp asks you to help him to implement the password check module. Given the password p and the hash h, check that h can be the hash for the password p.
Your program should answer t independent test cases.
思路:
暴力枚举
代码:
#include<bits/stdc++.h>
using namespace std;
map<char, int> Mp;
string p, s;
bool Check(int x)
{
map<char, int> Tmp;
Tmp = Mp;
for (int i = 0;i < (int)p.size();i++)
{
if (Tmp[s[i+x]] < 0)
return false;
Tmp[s[i+x]]--;
}
for (auto v: Tmp) if (v.second > 0)
return false;
return true;
}
int main()
{
int t;
cin >> t;
while(t--)
{
Mp.clear();
cin >> p >> s;
for (int i = 0;i < (int)p.size();i++)
Mp[p[i]]++;
bool flag = false;
for (int i = 0;i < (int)s.size();i++) if (Check(i))
{
flag = true;
break;
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
Educational Codeforces Round 78 (Rated for Div. 2) A. Shuffle Hashing的更多相关文章
- 【cf比赛记录】Educational Codeforces Round 78 (Rated for Div. 2)
比赛传送门 A. Shuffle Hashing 题意:加密字符串.可以把字符串的字母打乱后再从前面以及后面接上字符串.问加密后的字符串是否符合加密规则. 题解:字符串的长度很短,直接暴力搜索所有情况 ...
- Educational Codeforces Round 78 (Rated for Div. 2) D. Segment Tree
链接: https://codeforces.com/contest/1278/problem/D 题意: As the name of the task implies, you are asked ...
- Educational Codeforces Round 78 (Rated for Div. 2) C. Berry Jam
链接: https://codeforces.com/contest/1278/problem/C 题意: Karlsson has recently discovered a huge stock ...
- Educational Codeforces Round 78 (Rated for Div. 2) B. A and B
链接: https://codeforces.com/contest/1278/problem/B 题意: You are given two integers a and b. You can pe ...
- Educational Codeforces Round 78 (Rated for Div. 2)B. A and B(1~n的分配)
题:https://codeforces.com/contest/1278/problem/B 思路:还是把1~n分配给俩个数,让他们最终相等 假设刚开始两个数字相等,然后一个数字向前走了abs(b- ...
- Educational Codeforces Round 78 (Rated for Div. 2)
A题 给出n对串,求s1,是否为s2一段连续子串的重排,串长度只有100,从第一个字符开始枚举,sort之后比较一遍就可以了: char s1[200],s2[200],s3[200]; int ma ...
- Educational Codeforces Round 78 (Rated for Div. 2) --补题
链接 直接用数组记录每个字母的个数即可 #include<bits/stdc++.h> using namespace std; int a[26] = {0}; int b[26] = ...
- Educational Codeforces Round 78 (Rated for Div. 2) 题解
Shuffle Hashing A and B Berry Jam Segment Tree Tests for problem D Cards Shuffle Hashing \[ Time Lim ...
- Educational Codeforces Round 78 (Rated for Div. 2) C - Berry Jam(前缀和)
随机推荐
- java知识体系(自我学习中)
java自我学习知识体系
- docker命令集合
#docker安装yum -y install docker-iodocker --version #启动Docker进程systemctl start dockersystemctl status ...
- maven基本知识的7个提问
在如今的互联网项目开发当中,特别是Java领域,Maven的仓库管理.依赖管理.继承和聚合等特性为项目的构建提供了一整套完善的解决方案. 这里我们通过7个关于Maven的提问来了解Maven的一些基本 ...
- 基础知识---const、readonly、static
const:静态常量,也称编译时常量(compile-time constants),属于类型级,通过类名直接访问,被所有对象共享! a.叫编译时常量的原因是它编译时会将其替换为所对应的值: b.静态 ...
- MySQL数据库 : 高级查询
根据某个字段删除重复的数据, 只保留一条: 比如uuid字段有重复的, 需要只保留一条数据, 让uuid字段不能重复, 则首先 group by uuid 查出所有数据的id最小的那条数据,作为dt表 ...
- .Net Core 学习路线图
今天看 草根专栏 这位大牛的微信公众号,上面分享了一张来自github的.net core学习路线图,贴在这里,好让自己学习有个方向,这么一大页竟然只是初级到高级的,我的个乖乖,太恐怖了. 感谢大牛 ...
- WebAPI HelpPage帮助页
WebAPI HelpPage是个插件,根据代码的注释生成API说明页,一目了然. 下面开始安装和配置 1.添加引用 先选择管理NuGet程序包,搜索 Microsoft.AspNet.WebApi. ...
- vscode 代码折叠快捷键,折叠所有/展开所有
1.折叠所有区域的快捷键:ctrl + k ctrl + 0 (这里是数字键0) 2.展开所有区域的快捷键:ctrl + j ctrl + j
- 基于roslyn的动态编译库Natasha
人老了,玩不转博客园的编辑器,详细信息转到:https://mp.weixin.qq.com/s/1r6YKBkyovQSMUgfm_VxBg 关键字:Github, NCC, Natasha,Ros ...
- moodle3.7中文语言包
Moodle官方有中文语言包,但是还有没有翻译的,为了提高用户体验,可以将部分未翻译的应用在Moodle网站管理中自己修改. 具体步骤: 先确定需要修改的关键字,也就是网站中没有翻译成中文的文字 在c ...