链接:

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.

思路:

暴力枚举

代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. map<char, int> Mp;
  4. string p, s;
  5. bool Check(int x)
  6. {
  7. map<char, int> Tmp;
  8. Tmp = Mp;
  9. for (int i = 0;i < (int)p.size();i++)
  10. {
  11. if (Tmp[s[i+x]] < 0)
  12. return false;
  13. Tmp[s[i+x]]--;
  14. }
  15. for (auto v: Tmp) if (v.second > 0)
  16. return false;
  17. return true;
  18. }
  19. int main()
  20. {
  21. int t;
  22. cin >> t;
  23. while(t--)
  24. {
  25. Mp.clear();
  26. cin >> p >> s;
  27. for (int i = 0;i < (int)p.size();i++)
  28. Mp[p[i]]++;
  29. bool flag = false;
  30. for (int i = 0;i < (int)s.size();i++) if (Check(i))
  31. {
  32. flag = true;
  33. break;
  34. }
  35. if (flag)
  36. cout << "YES" << endl;
  37. else
  38. cout << "NO" << endl;
  39. }
  40. return 0;
  41. }

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. 分布式事物解决方案-TCC

    分布式框架下,如何保证事物一致性一直是一个热门话题.当然事物一致性解决方案有很多种(请参考:分布式事物一致性设计思路),我们今天主要介绍TCC方案解决的思路.以下是参与设计讨论的一种解决思路,大家有问 ...

  2. UVA 10789 题解

    Prime Frequency Given a string containing only alpha-numerals (0-9,A-Z and a-z) you have to count th ...

  3. (转)WEB页面导出为Word文档后分页&横向打印的方法

    <html>    <HEAD>        <title>WEB页面导出为Word文档后分页&横向打印的方法 </title>    < ...

  4. EF 通过导航添加数据

    Fluent Api是指定模型与数据库表之间的对应关系 //一对多 this.HasOptional(x => x.主表).WithMany(x => x.多表).HasForeignKe ...

  5. np.broadcast_to()的函数使用及维度增加的表达

    import numpy as npanchors=np.ones((2,3))anchor = np.broadcast_to(anchors, (5,)+anchors.shape) # 标红字体 ...

  6. 【selenium】基于python语言,如何用select选择下拉框

    在项目测试中遇到了下拉框选择的控件,来总结下如何使用select选择下拉框: 下图是Select类的初始化描述,意思是,给定元素是得是select类型,不是就抛异常.接下来给了例子:要操作这个sele ...

  7. 浓缩版java8新特性

    目录 一.Lambda 1.定义/设计原因 2.结构 3.规则 4.使用 二.函数式接口 1.定义 2.设计原因 3.使用 三.方法引用 1.定义/设计原因 2.使用 四.接口的默认方法 1.定义 2 ...

  8. Oracle PLSQL游标、游标变量的使用

    参考文章:https://www.cnblogs.com/huyong/archive/2011/05/04/2036377.html 在 PL/SQL 程序中,对于处理多行记录的事务经常使用游标来实 ...

  9. IDEA Mac 快捷键

    智能提示 ⌘ -> command ⇧ -> shift ⌥ -> option ⬆ -> 上箭头 ⬇ -> 下箭头 ⌃ -> Control 编辑 快捷键 说明 ...

  10. Java的自动拆装箱与Integer的缓存机制

    转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/10832303.html 一:基本类型与包装类型     我们知道,Java有8大基本数据类型,4整2浮1符1 ...