链接:

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的更多相关文章

  1. 【cf比赛记录】Educational Codeforces Round 78 (Rated for Div. 2)

    比赛传送门 A. Shuffle Hashing 题意:加密字符串.可以把字符串的字母打乱后再从前面以及后面接上字符串.问加密后的字符串是否符合加密规则. 题解:字符串的长度很短,直接暴力搜索所有情况 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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- ...

  6. Educational Codeforces Round 78 (Rated for Div. 2)

    A题 给出n对串,求s1,是否为s2一段连续子串的重排,串长度只有100,从第一个字符开始枚举,sort之后比较一遍就可以了: char s1[200],s2[200],s3[200]; int ma ...

  7. Educational Codeforces Round 78 (Rated for Div. 2) --补题

    链接 直接用数组记录每个字母的个数即可 #include<bits/stdc++.h> using namespace std; int a[26] = {0}; int b[26] = ...

  8. 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 ...

  9. Educational Codeforces Round 78 (Rated for Div. 2) C - Berry Jam(前缀和)

随机推荐

  1. Docker笔记:常用服务安装——Nginx、MySql、Redis(转载)

    转载地址:https://www.cnblogs.com/spec-dog/p/11320513.html 开发中经常需要安装一些常用的服务软件,如Nginx.MySql.Redis等,如果按照普通的 ...

  2. PowerShell的异常处理办法

    $ErrorActionPreference = 'Stop' Try{     # C:\xxx 不存在     Copy-Item C:\xxx -ErrorAction Stop } Catch ...

  3. vue学习面向对象,在项目中怎么用呢?

    面向对象感觉很牛逼,可是在项目中怎么用呢? 我至今见到的用法,写了一个用户对象. 效果:只要执行了new User(userInfo)就会在cookie,localStorage存放数据. 所以最简单 ...

  4. 关于wordpress4.8中的Twenty Seventeen主题的主题选项增加章节的实现

    我这里的wordpress版本是4.8  默认的主题是 Twenty Seventeen 我想实现的事 主题选项的首页  多增加2个章节 默认是只有4个章节  我想在增加2个 到6个 看下实现后的效果 ...

  5. Python range() 函数用法及字符串下标

    range() 函数用法 range() 函数可创建一个整数列表,一般用在 for 循环中 range() 函数的表示方法: range(start, stop[, step]) start: 计数从 ...

  6. 字符串替换replace方法

    字符串替换replace方法: http://www.w3school.com.cn/jsref/jsref_replace.asp http://www.cnblogs.com/skywang/ar ...

  7. Spring Boot2(八):性感banner,在线发牌

    本文在个人技术博客[鸟不拉屎]同步发布,详情可猛戳 亦可扫描文章末尾二维码关注个人公众号[鸟不拉屎] emmm,没有啥前言 玩过SpringBoot的都知道,SpringBoot启动的时候,默认会在控 ...

  8. WDA基础十八:Select option配置

    为了省代码...为了方便管理WDA的查询条件... 首先建配置表: 说明: 上面的KEY基本都是维护的维度,可以根据销售组织,根据用户组,根据组件,根据SELECT OPTION的不同...等等,可以 ...

  9. vmware安装后设置网络

    CentOS安装无法ping 出现Name or service not known   [root@www ~]# ping www.baidu.comping: www.baidu.com: Na ...

  10. windows定期删除文件

    :: 定时清理客户端上传导入包文件 @echo off title 清理客户端上传导入包文件 :: 导入包文件目录 set log_dir="F:\http\uploadzip\web\ht ...