算法.开放寻址法


#include
#include
#include
using namespace std;
const int N = 10003,null=0xf3f3f3;
int h[N];


int find(int x)
{
    int k = (x % N + N) % N;
    while (h[k] != null&&h[k]!=x)
    {
        k++;
        if (k == N)k = 0;
    }
}

int main()
{
    memset(h, null, sizeof(h));
   
    int n,x;
    string a;
    cin >> n;
    while (n--)
    {
        cin >> a >> x;
        if (a == "I")
        {
            h[find(x)];
        }
        else {
            if (find(x)!=null)
            {
                cout << "Yes";
            }
            else cout << "No";
        }
    }
    return 0;
}

你可能感兴趣的:(算法)