zoukankan      html  css  js  c++  java
  • 81: luogu3370 hash

    hash 模板题

    #include <bits/stdc++.h>
    
    using namespace std;
    
    #define ULL unsigned long long
    const ULL Mod = 212370440130137957ll;
    
    char c[10010];
    int pri = 233317;
    ULL number[10010];
    
    inline ULL Hash1(char s[]) {
        int Len = strlen(s);
        ULL base = 111, ret = 0;
        for(int i = 0; i < Len; i ++) ret = (ret * base + s[i]) % Mod + pri;
        return ret;
    }
    
    inline ULL Hash2(char s[]) {
        int Len = strlen(s);
        ULL base = 131, ret = 0;
        for(int i = 0; i < Len; i ++) ret = (ret * base + (ULL)s[i]) % Mod + pri;
        return ret;
    }
    
    inline ULL Hash3(char s[]) {
        int Len = strlen(s);
        ULL base = 4571, ret = 0;
        for(int i = 0; i < Len; i ++) ret = (ret * base + s[i]) % Mod + pri;
        return ret;
    }
    
    int main() {
        int n;
        cin >> n;
        for(int i = 1; i <= n; i ++) {
            scanf("%s", c);
            ULL Num = (((Hash1(c) * 123) % Mod * Hash2(c) * 345 % Mod) * Hash3(c)) % Mod;
            number[i] = Num;
        }
        sort(number + 1, number + n + 1);
        int tot = 1;
        for(int i = 1; i < n; i ++) if(number[i] != number[i + 1]) tot ++;
        cout << tot;
        
        return 0;
    }
  • 相关阅读:
    团队作业(三):确定分工
    团队作业(二):项目选题
    团队冲刺DAY3
    团队冲刺DAY4
    团队冲刺DAY6
    团队冲刺DAY1
    团队冲刺DAY5
    团队冲刺DAY7
    团队作业(四):描述设计
    【自学Spring Boot】什么是Spring Boot
  • 原文地址:https://www.cnblogs.com/shandongs1/p/9858760.html
Copyright © 2011-2022 走看看