Pagini recente » Cod sursa (job #1663129) | Cod sursa (job #1916714) | Cod sursa (job #2563695) | Cod sursa (job #1156937) | Cod sursa (job #104024)
Cod sursa(job #104024)
using namespace std;
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <ctime>
#define maxn 60003
#define maxlog 17
#define pb push_back
vector<int> H[maxn][maxlog];
inline void insert(int v)
{
int h1=(v%maxn);
int h2=(v%maxlog);
H[h1][h2].pb(v);
}
inline int find(int v)
{
vector<int>::iterator it, last;
int h1=(v%maxn);
int h2=(v%maxlog);
for(it=H[h1][h2].begin(), last=H[h1][h2].end(); it!=last;++it)
if(*it==v)return 1;
return 0;
}
int main()
{
srand(time(0));
double start=clock();
for(int i=1;i<=1000000;++i) insert(rand());
for(int i=1;i<=1000000;++i) find(rand());
printf("%lf\n", (clock()-start)/(double)CLOCKS_PER_SEC);
return 0;
}