南阳oj 寻找球号(二) 数据结构 题目138
来源:互联网 发布:淘宝电动车便宜 编辑:程序博客网 时间:2024/06/05 06:52
刚开始我用普通的做了不下30遍 老师Runtime Error
//普通顺序表超时了
#include<stdio.h>
#include<string.h>
const int N=100000;
struct node
{
int length;
int num[N];
};
typedef struct node linklist;
void chu(linklist *head)
{head->length=0;}
void in(linklist *head,int l)
{
head->num[head->length]=l;
head->length++;
}
bool sert(linklist *head,int n)
{
for(int i=0;i<head->length;i++)
{
if(head->num[i]==n) return true;
}
return false;
}
main()
{
linklist head;
chu(&head);
int n,k,m,h;
char s[5];
scanf("%d",&n);
while(n--)
{
scanf("%s",s);
scanf("%d",&k);
if(strcmp(s,"ADD")==0)
{
for(int j=0;j<k;j++)
scanf("%d",&h);
in(&head,h);}
else
{
for(int j=0;j<k;j++)
{
scanf("%d",&m);
if(sert(&head,m)) printf("YES\n");
else printf("NO\n");
}
}
}
}
//Hans表做的
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
const int maxn=1000002;
const int fib=111123;//这个值是看别人的目前我也不了解
int Hash[maxn],head[maxn],next[maxn];//head相当于每一个散列表的头节点,当前节点的下一个节点
int top;
void add(int m)//插入元素
{
int key=m%fib;
next[top]=head[key];
head[key]=top;
Hash[top]=m;
top++;
}
bool query(int m)//查询是否与m相同的元素
{
int key=m%fib;
for(int i=head[key];i>-1;i=next[i])
{
if(Hash[i]==m)
return true;
}
return false;
}
main()
{
int n,m,num;
char s[5];
scanf("%d",&n);
memset(head,-1,sizeof(head));//赋初值
top=0;
while(n--)
{
scanf("%s %d",s,&m);
if(s[0]=='A')
{
for(int i=0;i<m;i++)
{
scanf("%d",&num);
add(num);
}
}
else
{
for(int i=0;i<m;i++)
{
scanf("%d",&num);
if(query(num)) printf("YES\n");
else printf("NO\n");
}
}
}
}
- 南阳oj 寻找球号(二) 数据结构 题目138
- 南阳oj 士兵杀敌(二) 题目116 NYOJ 数据结构
- 南阳oj NYoj 寻找最大数(三) 题目1057
- 南阳oj NYoj 数据结构 士兵杀敌(一) 题目108
- 南阳oj NYOJ 数据结构 题目93 汉若塔(三)
- 南阳oj 士兵杀敌(三) 题目119 数据结构
- 南阳oj 表达式求值 题目305 数据结构
- 阶乘因式分解(二)【南阳oj 题目70】
- 南阳oj NYOJ 寻找最大数 题目236
- 南阳 oj 表达式求值 题目35 数据结构 NYO题目链接
- 南阳oj 数据结构 括号配对 题目2 NYOJ
- 南阳 oj NYoj 数据结构 最小数 题目1073
- 南阳oj 数据结构 题目739 笨蛋难题四
- 南阳oj NYOJ 动物统计加强版 数据结构 题目290
- 南阳oj 郁闷的c小加(二) 题目267
- 南阳理工oj 题目116 士兵杀敌(二)树状数组
- 南阳OJ 116-士兵杀敌(二)
- 南阳 oj 176 整数划分(二)
- gtk防止窗口最大化
- mysql游标的使用
- Online Judge System For SzNOI 题库 语法百题 c++ d023
- Python 代码风格 和 PEP8
- Arcgis Server开发使用query报错
- 南阳oj 寻找球号(二) 数据结构 题目138
- pandas options and settings
- memory balloon
- gnome配置
- IOS 二维码生成 同时打开网页
- 系统备份只需简单3步走
- Tomcat本地服务器搭建
- Sybase 的convert函数
- 大数据征信的应用和启示:ZestFinance的基于大数据的信用评估技术