Find the ball number (1)

Source: Internet
Author: User
Find the ball number (1)

Description

A game is popular in a country. The game rule is: in a pile of balls, each ball has an integer number I (0 <= I <= 100000000), which can be repeated, A random integer K (0 <= k <= 100000100) is used to determine whether the ball number k is in this heap ("yes"; otherwise, "no "), answer the question first to win. One person wants to play this game, but he is very lazy. He hopes that you can help him win.

 
Input
The first row has two integers, m, n (0 <= n <= 100000,0 <= m <= 1000000); M indicates that there are m balls in the heap, N indicates that the game is played n times. Next, enter m + n integers. The first m represents the number I of the M balls, and the last n represents the random integer k in each game.
Output
Output "yes" or "no"
Sample Input
6 423 34 46 768 343 3432 4 23 343
Sample output
NONOYESYES

 #include <iostream>#include <set>using namespace std;int main(){ set<int>s; int m,n; int aa[1000010]; int a1; cin>>m>>n; for(int i=0;i<m;i++) {     cin>>a1;     s.insert(a1); } for(int i=0;i<n;i++)     cin>>aa[i]; for(int i=0;i<n;i++) {     if(s.find(aa[i])!=s.end())         cout<<"YES"<<endl;     else         cout<<"NO"<<endl; }    return 0;}        

 

Find the ball number (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.