当前位置:网站首页>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
边栏推荐
- VLAN experiment
- Drools dynamically add, modify, and delete rules
- Deep Copy Event bus
- JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)
- 线性DP AcWing 898. 数字三角形
- 模数转换器(ADC) ADE7913ARIZ 专为三相电能计量应用而设计
- In development, why do you find someone who is paid more than you but doesn't write any code?
- LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
- JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
- When uploading a file, the server reports an error: iofileuploadexception: processing of multipart / form data request failed There is no space on the device
猜你喜欢
Deep copy event bus
Sweetheart leader: Wang Xinling
Anxiety of a 211 programmer: working for 3 years with a monthly salary of less than 30000, worried about being replaced by fresh students
中国交通标志检测数据集
bellman-ford AcWing 853. 有边数限制的最短路
AI中台技术调研
2.7 binary tree, post order traversal - [FBI tree]
8 examples of using date commands
NTMFS4C05NT1G N-CH 30V 11.9A MOS管,PDF
C#运算符
随机推荐
LeetCode—剑指 Offer 37、38
1380. Lucky numbers in the matrix [two-dimensional array, matrix]
This "little routine" is set on the dough cake of instant noodles. No wonder programmers are always hungry
Does C language srand need to reseed? Should srand be placed in the loop? Pseudo random function Rand
Floyd AcWing 854. Floyd求最短路
单指令多数据SIMD的SSE/AVX指令集和API
深拷貝 事件總線
OpenCV中cv2.VideoWriter_fourcc()函数和cv2.VideoWriter()函数的结合使用
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
Drools terminates the execution of other rules after executing one rule
ArrayList与LinkedList效率的对比
JS8day(滚动事件(scroll家族),offset家族,client家族,轮播图案例(待做))
传感器 ADXL335BCPZ-RL7 3轴 加速度计 符合 RoHS/WEEE
arcgis js 4. Add pictures to x map
Anti shake throttle
Drools executes the specified rule
线性DP AcWing 902. 最短编辑距离
There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes
About asp Net MVC project in local vs running response time is too long to access, the solution!
C#运算符