#include<bits/stdc++.h>
using namespace std;
int main() { //开放定址法(增量取法采用线性探测再散列)构造哈希表
int n, m, p;
cin >> n >> m >> p;
int i, j, temp;
int a[10000] = {}, b[10000] = {};
for (i = 0; i < p; i++) { //初始化
b[i] = 9999;
}
for (i = 0; i < n; i++) { //录入
cin >> a[i];
}
int x;
cin >> x;
int x_yushu = x % p;
for (i = 0; i < n; i++) { //根据余数,将a[i]录入到b中
temp = a[i] % p;
for (j = temp; j < temp + p; j++) {
if (b[j % p] == 9999) {
b[j % p] = a[i];
break;
}
}
}
int num = 0, temp1 = 0, temp2 = 0; //num查找次数
for (i = x_yushu; i < x_yushu + p; i++) {
if (b[i % p] == x) { //找到了
num++;
temp1 = 1;
break;
}
if (b[i % p] == 9999) { //该位置没有数据,即没找到
temp2 = 1;
num++;
break;
}
num++;
}
//当全部遍历没找到,或者找的位置已经没有数据时
if ((i % p == x_yushu && temp1 != 1) || temp2 == 1) {
cout << "Failure " << num << endl;
}
else {
cout << "Success " << num << endl;
}
return 0;
}
测试结果: