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 web开发入门十(idea创建maven SSM项目)基于intellig idea
一.搭建项目骨架 二.配置pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xm ...
- Java-volatile底层实现原理
一.volatile 代码 package jvm; public class VolatileVisibilityTest { private static boolean initFlag = f ...
- swiper轮播,添加鼠标移入事件停止轮播,移出重新开启轮播
已测过无问题.
- kubernetes使用阿里云cpfs持久存储
目录 简介 安装cpfs客户端 kubernetes使用cfs作为持久存储 简介 cpfs的具体介绍可参考这里: https://help.aliyun.com/document_detail/111 ...
- 常见框架和WSGI协议
三大框架对比 Django 大而全 自带的功能特别特别多 类似于航空母舰 有时候过于笨重 Flask 小而精,只保留了核心功能,其他可以自由选择 第三方的模块特别特别多,如果将flask第三方模块全部 ...
- [转帖]SQL Server DBCC命令大全
SQL Server DBCC命令大全 原文出处:https://www.cnblogs.com/lyhabc/archive/2013/01/19/2867174.html DBCC DROPC ...
- Blockstack: A Global Naming and Storage System Secured by Blockchains
作者:Muneeb Ali, Jude Nelson, Ryan Shea, and Michael Freedman Blockstack Labs and Princeton University ...
- 重绘MenuStrip 控件
重绘MenuStrip控件 效果如图: 首先添加 CustomProfessionalRenderer类 用于重绘控件菜单样式 /// <summary> /// 自定义MenuStrip ...
- Java代码中可以优化性能的小细节
避免对boolean类型的判定 反例: 12 if("a".equles("a")==true)`{} 正例: 12 if(Objects.equles(&qu ...
- vim 如何复制文件中多行到另一个文件
1.打开文件 vim a.txt b.tx 或者 vim *.txt 2.文件间切换 :n 切换到下一个文件 :wn 保存再切换 :N 到上一个文件 :wN 保存再切换 :.= 看当前行 3.假定当前 ...