codevs 1230_元素查找_hash
来源:互联网 发布:淘宝药品需求清单 编辑:程序博客网 时间:2024/05/22 13:31
题目描述
给出n个正整数,然后有m个询问,每个询问一个整数,询问该整数是否在n个正整数中出现过。
思路
水hash,复习一下。。。
O(n)
#include <stdio.h>#define M 100007int a[M+1];int insert(int x){ int i=x; while (a[i]!=0&&a[i]!=x) i++; a[i]=x;}int find(int x){ int i=x; while (a[i]!=x&&a[i]!=0) i++; if (a[i]==x) return 1; else return 0;}int main(){ int n,m; scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) { int x; scanf("%d",&x); insert(x); } for (int i=1;i<=m;i++) { int x; scanf("%d",&x); if (find(x)) printf("YES\n"); else printf("NO\n"); }}
1 0
- codevs 1230_元素查找_hash
- CODEVS 1230 元素查找
- CODEVS 1230元素查找
- CODEVS 1230 元素查找
- 【codevs 1230】元素查找
- CODEVS 1230 元素查找
- CODEVS 1230 元素查找
- 【CODEVS 1230】元素查找 哈希表
- codevs 1230 元素查找(hash)
- codevs 1230 元素查找 二分
- [Codevs 1230]元素查找(手写哈希表)
- 【codevs 1230】元素查找 splay……
- codevs 1230 元素查找(hash)
- SSL 2482_上海红茶馆_hash
- 1230 元素查找
- codevs 2664_上厕所
- 字符串_hash
- 网易_在数组中查找前K个元素
- Quest 公司的Shareplex 与 GoldenGate比较
- Linux 运维必备
- leetcode-191- Number of 1 Bits
- 用vb代开关闭exe文件
- RadioButton动态添加以及需要注意的问题
- codevs 1230_元素查找_hash
- Outlook.com 系列邮箱 POP3 及 IMAP 设置方法
- Android 数据流量(3G,4G)与wifi 转换实时监听
- ES6 学习笔记
- git checkout 命令详解
- Qt5.7 Qt for Embedded Linux
- 新手村之过程函数与递归
- (一)1.4JDK安装与环境变量配置及环境变量相关问题
- TS科普23 ES PES TS关系