Pagini recente » Cod sursa (job #3246339) | Cod sursa (job #2524049) | Cod sursa (job #781154) | Cod sursa (job #2451098) | Cod sursa (job #3246353)
/*
* Inlantuire directa
* variem functiile de dispersie
* sa facem multe teste
*/
/* Metode de testare:
* 1) Generarea numerelor random pe interval;
* 2) Putem genera teste adversariale pentru functile de Hash;
* 3) Generare numere random si aleg cu +- 10^9 numarul in zona (Clustare);
*/
#include <fstream>
#include <iostream>
#include <list>
#include <vector>
#define p 1000003
std::ifstream fin("hashuri.in");
std::ofstream fout("hashuri.out");
const int NMAX = (int)1e6;
std::vector<std::list<int>> v;
int myHash(int x) { return x % p; }
bool inHash(int x) {
for (auto a : v[myHash(x)]) {
if (a == x) {
return true;
}
}
return false;
}
void insertHash(int x) {
if (!inHash(x)) {
v[myHash(x)].push_back(x);
}
}
void removeHash(int x) {
if (inHash(x)) {
v[myHash(x)].remove(x);
}
}
int main(int argc, char *argv[]) {
if (!fin.is_open()) {
std::cout << "Couldn't open file!\n";
return 1;
}
int n, op, x;
fin >> n;
v.resize(NMAX);
for (int i = 0; i < n; i++) {
fin >> op >> x;
if (op == 1) {
insertHash(x);
} else if (op == 2) {
removeHash(x);
} else if (op == 3) {
fout << inHash(x) << '\n';
}
}
return 0;
}