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(前缀和)
随机推荐
- 【Struts】Struts框架配置详解
1.首先将所必须的Jar包放到项目的WebRoot/WEB-INF/lib目录下. 如果你没有这些Jar文件,你可以到Struts官网上下载:http://struts.apache.org/.因为经 ...
- 五年微软DevOps MVP (也称TFS MVP)
笔者有幸第五次被微软授予MVP称号,高兴之余,在这里简单的介绍一下MVP的基本情况: 谁是 MVP? Microsoft 最有价值专家 (MVP) 是热情地与社区分享知识的技术专家.他们总是处于&qu ...
- Oracle性能调优之物化视图用法简介
目录 一.物化视图简介 二.实践:创建物化视图 一.物化视图简介 物化视图分类 物化视图分类,物化视图语法和as后面的sql分为: (1) 基于主键的物化视图(主键物化视图) (2)基于Rowid的物 ...
- windows 下验证文件MD5
CertUtil -hashfile C:\Users\admin\Downloads\aaa.txt MD5 CertUtil -hashfile C:\Users\admin\Downloads\ ...
- 常用mysql系统表及命令
常用系统表查看当前数据库连接ip信息– select * from information_schema.PROCESSLIST 当前mysql实例中所有数据库的信息– select * from i ...
- 【BZOJ4487】[JSOI2015]染色问题(容斥)
[BZOJ4487][JSOI2015]染色问题(容斥) 题面 BZOJ 题解 看起来是一个比较显然的题目? 首先枚举一下至少有多少种颜色没有被用到过,然后考虑用至多\(k\)种颜色染色的方案数. 那 ...
- [cf 1264 C] Beautiful Mirrors with queries
题意: 你有$n$个魔镜,第$i$个魔镜有$p_{i}$的概率说你美. 从第1天开始,你会依次询问魔镜$1-n$你美不美. 若第$i$个魔镜说你美则你明天会继续询问第$i+1$个魔镜. 否则你明天会从 ...
- LinkedHashMap 的核心就 2 点,搞清楚,也就掌握了
HashMap 有一个不足之处就是在迭代元素时与插入顺序不一致.而大多数人都喜欢按顺序做某些事情,所以,LinkedHashMap 就是针对这一点对 HashMap 进行扩展,主要新增了「两种迭代方式 ...
- 【C#】Winform 令人困擾的畫面閃爍問題解法
DoubleBuffered = true 如果 Control 沒有這個屬性,可以使用我下列擴充函式進行設定︰ public static void SetDoubleBuffered<T&g ...
- 基于vue+springboot+docker网站搭建【六】安装中间件
安装中间件 去另外一台2核4G的机器先安装docker,然后安装后台项目使用的中间件 一.mysql 下载镜像:docker pull mysql:5.7 启动镜像实例:docker run -p 3 ...