美文网首页
1078 Hashing(25 分)

1078 Hashing(25 分)

作者: zjh3029 | 来源:发表于2018-09-07 12:28 被阅读0次
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <cmath>
    #include<queue>
    #include<string>
    using namespace std;
    vector<int> in, level;
    #define C(X) cout<<X
    #define ST system("pause")
    #pragma warning(disable:4996)
    
    int M, N, a;
    vector<bool> v;
    int isprime(int data)
    {
        if (data==1) data += 1;
        for (int i = 2; i <(int)sqrt((int)data)+1; i++)
        {
            if (data%i==0)
            {
                data++;
                i = 1;
            }
        }
        return data;
    }
    
    string ins(int data,int b)
    {
        for (int i = 0; i < b-1; i++)
        {
            int temp = (data + i * i) % b;
            if(v[temp]==false)
            {
                v[temp] = true;
                return to_string(temp)+" ";
            }
        }
        return "- ";
    }
    
    int main() {
        cin >> M >> N;
        M = isprime(M);
        v.resize(M, false);
        for (int i = 0; i < N; i++)
        {
            cin >> a;
            string x=ins(a,M);
            if (i!=N-1)
                C(x);
            else
            {
                x.erase(x.end() - 1, x.end());
                C(x);
            }
        }
    
        ST;
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:1078 Hashing(25 分)

          本文链接:https://www.haomeiwen.com/subject/thqcgftx.html