当前位置:网站首页>Hash table acwing 840 Simulated hash table
Hash table acwing 840 Simulated hash table
2022-07-02 12:42:00 【T_ Y_ F666】
Hashtable AcWing 840. Simulation hash table
Original link
AcWing 840. Simulation hash table
Algorithm tags
Hashtable
Ideas

Zipper method

Open addressing
Code
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>b;--i)
using namespace std;
const int N = 100003;
int a[N], e[N], h[N], ne[N], idx;
int s;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
// Head insertion Insert the data into the corresponding hash The value is k Of hash In the table
void insert(int x){
// Ensure that negative numbers can also be mapped to hash In the table The modulo number is a prime number Conflicts can be minimized
int k=(x%N+N)%N;
e[idx]=x;
ne[idx]=h[k];
h[k]=idx++;
}
bool find(int x){
int k=(x%N+N)%N;
for(int i=h[k]; i!=-1; i=ne[i]){
if(e[i]==x){
return true;
}
}
return false;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
memset(h, -1, sizeof h);
int n=read();
while(n--){
char op[2];
scanf("%s", op);
int x=read();
if(op[0]=='I'){
insert(x);
}else{
if(find(x)){
puts("Yes");
}else{
puts("No");
}
}
}
return 0;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
猜你喜欢
![2.7 binary tree, post order traversal - [FBI tree]](/img/6b/1ded3632cc69329d7b2762ce47fdbc.jpg)
2.7 binary tree, post order traversal - [FBI tree]

JS8day(滚动事件(scroll家族),offset家族,client家族,轮播图案例(待做))

In development, why do you find someone who is paid more than you but doesn't write any code?

JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)

Distributed machine learning framework and high-dimensional real-time recommendation system

"As a junior college student, I found out how difficult it is to counter attack after graduation."

AAAI 2022 | Peking University & Ali Dharma Institute: pruning and compression of pre training language model based on comparative learning

Docker-compose配置Mysql,Redis,MongoDB

The programmer and the female nurse went on a blind date and spent 360. He packed leftovers and was stunned when he received wechat at night

Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)
随机推荐
Oracle从入门到精通(第4版)
Find the common ancestor of any two numbers in a binary tree
async/await 异步函数
Drools executes string rules or executes a rule file
High performance erasure code coding
[FFH] little bear driver calling process (take calling LED light driver as an example)
BOM DOM
正确遍历EntryList方法
Why do programmers have the idea that code can run without moving? Is it poisonous? Or what?
Floyd AcWing 854. Floyd求最短路
JSON序列化 与 解析
百款拿来就能用的网页特效,不来看看吗?
线性DP AcWing 902. 最短编辑距离
Programmers can't find jobs after the age of 35? After reading this article, you may be able to find the answer
哈希表 AcWing 840. 模拟散列表
AI mid stage technology research
C#修饰符
NTMFS4C05NT1G N-CH 30V 11.9A MOS管,PDF
About asp Net MVC project in local vs running response time is too long to access, the solution!
MySQL and PostgreSQL methods to grab slow SQL