Hash+set codeforces Round #291 (Div. 2) C. Watto and mechanism

Source: Internet
Author: User

Topic Portal

1 /*2 Hash+set: The hash value of each string is stored in the set container first, and then enumerated for each of the strings of each query3 It is not difficult to understand the existence of a replacement string with the Find function of set. In addition, I would like to use the 64-bit natural overflow WA, not clear4 */5 /************************************************6 * Author:running_time7 * Created time:2015-8-5 13:05:498 * File Name:D. cpp9  ************************************************/Ten  One#include <cstdio> A#include <algorithm> -#include <iostream> -#include <sstream> the#include <cstring> -#include <cmath> -#include <string> -#include <vector> +#include <queue> -#include <deque> +#include <stack> A#include <list> at#include <map> -#include <Set> -#include <bitset> -#include <cstdlib> -#include <ctime> - using namespacestd; in  - #defineLson L, Mid, RT << 1 to #defineRson mid + 1, R, RT << 1 | 1 +typedefLong Longll; - Const intMAXN = 6e5 +Ten; the Const intINF =0x3f3f3f3f; * Const intMOD = 1e9 +7; $ Const intKEY =257;Panax Notoginseng CharS[MAXN]; - Set<ll>S; the ll HA[MAXN]; + intN, M; A  the voidInitvoid) { +ha[0] =1; -      for(intI=1; i<maxn; ++i) Ha[i] = ha[i-1] * KEY%MOD; $ } $  -ll Get_hash (Char*s) { -     intLen =strlen (s); thell res =0; -      for(intI=0; i<len; ++i) {Wuyires = (RES * KEY + s[i])%MOD; the     } -     returnRes; Wu } -  About BOOLJudgeChar*s) { $     intLen =strlen (s); -ll h =Get_hash (s); -      for(intI=0; i<len; ++i) { -          for(LL Ch='a'; ch<='C'; ++ch) { A             if(ch = = S[i])Continue; +             if(S.find ((((ch-s[i)) * ha[len-i-1] + h)% mod + MoD)% mod)! = S.end ())return true; the         } -     } $     return false; the } the  the intMainvoid)    {//codeforces Round #291 (Div. 2) C. Watto and mechanism the init (); -      while(SCANF ("%d%d", &n, &m) = =2) { in s.clear (); the          for(intI=1; i<=n; ++i) { thescanf ("%s", s); About S.insert (Get_hash (S)); the         } the          for(intI=1; i<=m; ++i) { thescanf ("%s", s); +             if(Judge (s)) puts ("YES"); -             ElsePuts ("NO"); the         }Bayi     } the  the     return 0; -}

Hash+set codeforces Round #291 (Div. 2) C. Watto and mechanism

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.