CODEVS 1230 元素查找
2017-12-04 17:36
429 查看
给出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
数据范围及提示 Data Size & Hint
所有数据都不超过10^8
c++自带的STL库
[cpp] view
plain c
#include<iostream> #include<cstdio> #include<set> using namespace std; #define maxn 100000 int main() { int n,m; int a,b; set<int>s; scanf("%d %d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",&a); s.insert(a); } for(int j=1;j<=m;j++) { scanf("%d",&b); if(s.count(b)==1) printf("YES\n"); else printf("NO\n"); } return 0; }
insert() 在集合中插入元素,count() 返回某个值元素的个数。
相关文章推荐
- CODEVS 1230 元素查找
- codevs 1230 元素查找(hash)
- 【CODE[VS]】1230 元素查找 二分
- CODEVS 1230元素查找
- codevs1230元素查找(hash)
- 【哈希表】CodeVs1230元素查找
- codevs 1230_元素查找_hash
- 【codevs1230】元素查找,弱弱的二分查找
- CODEVS 1230 元素查找
- codevs 1230 元素查找 二分
- 元素查找(codevs 1230)
- 【哈希表】CODEVS1230 元素查找
- AC日记——元素查找 codevs 1230
- CODE[VS] 1230 元素查找
- 1230 元素查找
- 【codevs 1230】元素查找
- 【CODEVS 1230】元素查找 哈希表
- 【codevs1553】互斥的数,二分查找是个好东西
- Code[VS] 1230 题解
- 1230 元素查找