开放寻址法

#include <iostream>
#include <cstring>
using namespace std;
const int N=200003,null=0x3f3f3f3f;
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;
}
return k;
}
int main()
{
int n;
cin>>n;
memset(h,null,sizeof h);
while(n--)
{
char op;
int x;
cin>>op>>x;
int k=find(x);
if(op=='I') h[k]=x;
else
{
if(h[k]!=null) puts("Yes");
else puts("No");
}
}
return 0;
}

posted @ 2022-03-29 13:21  小白QIU  阅读(83)  评论(1)    收藏  举报