UVA 10474 Where is the Marble?

Source: Internet
Author: User

Original question:
Raju and Meena love-to-play with marbles. They has got a lot of
Marbles with numbers written on them. At the beginning, Raju would place the marbles one after another in ascending order of the numbers written on them. Then Meena would ask Raju to find the first marble with a certain number. She would count 1 ... 2 ... 3. Raju gets one point to correct answer, and Meena gets the point if Raju fails. After some fixed number of trials the game ends and the player with maximum points wins. Today it ' s your chance to play as Raju. Being the Smart kid, you ' d be taking the favor of a computer. But don ' t underestimate Meena, she had written a program to keep track how much time you ' re taking to give all the answers . So now you have to write a program,which would help you in your role as Raju.
Input
There can multiple test cases. Total no of test cases was less than 65. Each test case consists begins with 2 integers:n the number of marbles and Q the number of queries Mina would make. The next
N lines would contain the numbers written on the N marbles. These marble numbers won't come in any particular order. Following q lines would have Q queries. Be assured, none of the input numbers is greater than 10000 and none of them are negative.
Input is terminated by a test case where N = 0 and Q = 0.
Output
For each test case output, the serial number of the case.
For each of the queries, print one line of output. The format of this line would depend upon whether or not the query number was written upon any of the marbles. The different formats is described
Below
• ' x found at Y ', if the first marble with number x is found at position y. Positions is numbered
1, 2, ..., N.
• ' x not found ', if the marble with number X was not present.
Look at the output for sample input for details.
Sample Input
4 1
2
3
5
1
5
5 2
1
3
3
3
1
2
3
0 0
Sample Output
case# 1:
5 found at 4
case# 2:
2 Not Found
3 found at 3
Lucky Cat's Chinese translation:
Raju and Meena like to play marbles, and they have a number of marbles on it. At the beginning, Raju is lined up in small to large numbers on the top of the marbles, and Meena asks Raju to find out where the first bead of the code is located. She'll count 1. 2 ... 3 ..., if Raju answer, he will have 1 points, whether Meena 1 points. After playing many times who scored more who won. Today you have an opportunity to play the role of Raju. Since you're both very smart kids, you'll be computing with computers, and Meena wrote a program to check how much time you spend answering all the questions.

Input

The input contains multiple test materials, the first column of each test is 2 positive integer n, q,n represents the number of marbles, Q represents the numbers of questions about the Meena of the test material. The next n column has an integer for each column, representing the number on the N marbles (not sorted). In the next Q column each column has an integer representing the problem (the number of the ball) that Meena asked. All input numbers are not larger than 10000 and are not negative.

When N=0, q=0 represents the end of the input. Please refer to sample Input.

Output

For each group of tests, please output a column, which is the first few tests. For each of the questions asked by the Meena, output a column with one of the following formats:

X found at Y      if the first number of marbles in X is found at position y (position starting from 1)
x      not found If you can't find the number X's marbles

Input format please refer to the sample Output.

#include <bits/stdc++.h>
using namespace std;
FStream in,out;
Vector<int> VI;
int main ()
{
    Ios::sync_with_stdio (false);
    int n,m,k=1;
    while (cin>>n>>m,n+m)
    {
        vi.clear ();
        for (int i=0;i<n;i++)
        {
            int t;
            cin>>t;
            Vi.push_back (t);
        }
        Sort (Vi.begin (), Vi.end ());
        cout<< "case#" <<k++<< ': ' <<endl;
        for (int i=1;i<=m;i++)
        {
            int t;
            cin>>t;
            Auto X=lower_bound (Vi.begin (), Vi.end (), t);
            if (X==vi.end () | | | *x!=t)
            {
                cout<<t<< "not Found" <<endl;
            }
            else
                cout<<t<< "found at" <<x-vi.begin () +1<<endl;
        }
    }
    return 0;
}

Answer:
Super simple problem, using two points to find Lower_bound can be past, with find can also be too.

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.