哈希表求助(悬赏……想什么呢,没有悬赏)
  • 板块学术版
  • 楼主KarmaticEnding
  • 当前回复4
  • 已保存回复4
  • 发布时间2023/7/29 16:36
  • 上次更新2023/11/3 07:02:49
查看原帖
哈希表求助(悬赏……想什么呢,没有悬赏)
642173
KarmaticEnding楼主2023/7/29 16:36

本机跑过了,但同样的数据,在AcWing上死活过不了,洛谷上也死活过不了

这是为什么呢?求大佬解答

题在这里

洛谷版题面在这里

代码在这里:

#include<bits/stdc++.h>
using namespace std;
struct node{
	int v;
	node *next;
};
node* chk[100010];
void Insert(int opn){
	int tmp=abs(opn)%100000;
	if(chk[tmp]->v==1000000002){
		chk[tmp]->v=opn;
	}
	else{
		node* tmpnode=chk[tmp];
		while(tmpnode->next!=NULL){
			tmpnode=tmpnode->next;
		}
		tmpnode->next=new node;
		tmpnode->next->v=opn;
	}
}
bool find_chk(int opn){
    int tmp=abs(opn)%100000;
    if(chk[tmp]->v!=opn){
		return false;
	}
	node* tmpnode=chk[tmp];
	while(tmpnode->next!=NULL){
		if(tmpnode->v==opn){
			return true;
		}
		tmpnode=tmpnode->next;
	}
	return false;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<100010;i++){
		chk[i]=new node;
		chk[i]->v=1000000002;
	}
	char opr;
	int opn;
	for(int y=0;y<n;y++){
		cin>>opr;
		scanf("%d",&opn);
		if(opr=='I'){
			Insert(opn);
		}
		else{
			if(find_chk(opn)){
				printf("Yes\n");
			}
			else{
				printf("No\n");
			}
		}
	}
	return 0;
}
2023/7/29 16:36
加载中...