http://acm.nyist.net/JudgeOnline/problem.php?pid=86

 

找球号(一)

时间限制:65535 KB
难度:3
 
描述
在某一国度里流行着一种游戏。游戏规则为:在一堆球中,每个球上都有一个整数编号i(0<=i<=100000000),编号可重复,现在说一个随机整数k(0<=k<=100000100),判断编号为k的球是否在这堆球中(存在为"YES",否则为"NO"),先答出者为胜。现在有一个人想玩玩这个游戏,但他又很懒。他希望你能帮助他取得胜利。
输入
第一行有两个整数m,n(0<=n<=100000,0<=m<=1000000);m表示这堆球里有m个球,n表示这个游戏进行n次。
接下来输入m+n个整数,前m个分别表示这m个球的编号i,后n个分别表示每次游戏中的随机整数k
输出
输出"YES"或"NO"
样例输入
6 4
23 34 46 768 343 343
2 4 23 343
样例输出
NO
NO
YES
YES
解题思路A:set容器 find功能
代码:
 1  #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <set>
 5 #include <algorithm>
 6 
 7 using namespace std;
 8 
 9 int main(){
10     int m,n,t;
11     set<int> se;
12     set<int>::iterator it;
13     scanf("%d %d",&m,&n);
14     for(int i=0;i<m;i++){
15         scanf("%d",&t);
16         se.insert(t);
17     }
18     for(int i=0;i<n;i++){
19         scanf("%d",&t);
20         it=se.find(t);
21         if(it==se.end())    puts("NO");
22         else    puts("YES");
23     }
24     return 0;
25 }
26         
View Code

相关文章:

  • 2021-11-17
  • 2021-08-11
  • 2022-03-01
  • 2021-05-27
  • 2022-12-23
  • 2021-06-10
  • 2022-12-23
  • 2021-08-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案