54分求大佬调
查看原帖
54分求大佬调
1164699
zyx13367095528楼主2024/7/29 13:46
54分求调
btw为什么哈希mod的值对答案精确性影响这么大啊


#include<set>
#include<vector>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
const int N = 23333;
string s;
int ans = 0;
vector<string>linker[N+2];
void insert()
{
    int hash = 1;
    for (int i = 0; i < s.size(); i++)
    {
        hash = (hash * 111 * 261 + s[i]) % N;
    }
    if (linker[hash].size() == 0)
    {
        linker[hash].push_back(s);
        ans++;
        return;
    }
    for (int i = 0; i < linker[hash].size(); i++)
    {
        if (linker[hash][i] == s)
        {
            return;
        }
        linker[hash].push_back(s);
        ans++;
    }

}
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> s;
        insert();
    }
    
    cout << ans;
    
    return 0;
}

2024/7/29 13:46
加载中...