Pagini recente » Cod sursa (job #1761809) | Cod sursa (job #1995058) | Cod sursa (job #321251) | Cod sursa (job #2065700) | Cod sursa (job #104021)
Cod sursa(job #104021)
using namespace std;
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <ctime>
#define maxn 100003
#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;
}