1230 元素查找
来源:互联网 发布:程序员表白代码 编辑:程序博客网 时间:2024/06/08 05:09
题目描述 Description
给出n个正整数,然后有m个询问,每个询问一个整数,询问该整数是否在n个正整数中出现过。
输入描述 Input Description
第一行两个整数 n 和m。
第二行n个正整数(1<=n<= 100000)
第三行m个整数(1<=m<=100000)
输出描述 Output Description
一共m行,若出现则输出YES,否则输出NO
样例输入 Sample Input
4 2
2 1 3 4
1 9
样例输出 Sample Output
YES
NO
#include <iostream>#include<string.h>#include <cstdio>#include<set>#include <algorithm>#include <cstring>#define MOD 9875321using namespace std;/*int main(){set<int> s;int i,j,k,n,m;cin>>n>>m;for (i=0; i<n; i++){cin>>k;s.insert(k);}for (i=0; i<m; i++){cin>>k;if (s.count(k)){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}return 0;}*/int a[100000]={0};int gethash(int n){int x=0;return n%MOD;}int main(){int i,j,k,n,m;cin>>n>>m;for (i=0; i<n; i++){cin>>k;a[gethash(k)] = 1;}for (i=0; i<m; i++){cin>>k;if (a[gethash(k)]){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}return 0;}
0 0
- CODEVS 1230 元素查找
- CODEVS 1230元素查找
- CODEVS 1230 元素查找
- 1230 元素查找
- 【codevs 1230】元素查找
- CODEVS 1230 元素查找
- CODEVS 1230 元素查找
- 【CODEVS 1230】元素查找 哈希表
- codevs 1230 元素查找(hash)
- codevs 1230 元素查找 二分
- 查找元素
- 元素查找
- 查找元素
- 查找元素
- 查找元素
- 查找元素
- 元素查找
- 元素查找
- leetcode 3. Longest Substring Without Repeating Characters
- C++必读书籍推荐
- C++学习笔记4:对象和类
- 关于异常
- html5第八课时,变形效果
- 1230 元素查找
- Android科普知识之recyclerView与标题栏的滑动变色
- html5第八课时,图片放大溢出解决
- 状态模式
- linux终端
- :before 和 :after的多用途实践 — 基础篇
- html5第八课时,移动的飞机
- 好网站推荐
- springmvc里的转发和重定向