Description

Raju and Meena love to play with Marbles. They have 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 for 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 will help you in your role as Raju.

Input

There can be multiple test cases. Total no of test cases is 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 will not come in any particular order. Following Q lines will have Q queries. Be assured, none of the input numbers are 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 will depend upon whether or not the query number is written upon any of the marbles. The two different formats are described below:

  • `x found at y', if the first marble with number x was found at position y. Positions are numbered 1, 2,..., N.
  • `x not found', if the marble with number x is 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
解题思路:用set容器查看是否含有这个元素,用vector来存所有元素,先排序,再查询。
AC代码:
 #include<bits/stdc++.h>
using namespace std;
int main(){
int n,q,x,y,cnt=;
set<int> se;vector<int> vec;
while(cin>>n>>q&&(n+q)){
se.clear();vec.clear();
while(n--){
cin>>x;
se.insert(x);
vec.push_back(x);
}
cout<<"CASE# "<<cnt++<<':'<<endl;
sort(vec.begin(),vec.end());
while(q--){
cin>>y;
if(!se.count(y))cout<<y<<" not found"<<endl;
else cout<<y<<" found at "<<(lower_bound(vec.begin(),vec.end(),y)-vec.begin()+)<<endl;
}
}
return ;
}
												

H - Where is the Marble?(set+vector)的更多相关文章

  1. C语言中.h和.c文件解析(很精彩)

    C语言中.h和.c文件解析(很精彩)   简单的说其实要理解C文件与头文件(即.h)有什么不同之处,首先需要弄明白编译器的工作过程,一般说来编译器会做以下几个过程: 1.预处理阶段 2.词法与语法分析 ...

  2. 逆向 stdio.h 函数库 fseek 函数(调试版本)

    0x01 fseek 函数 函数原型:int fseek(FILE *stream, long int offset, int whence) 函数功能:设置流 stream 的文件位置为给定的偏移 ...

  3. 逆向 stdio.h 函数库 fopen 函数(调试版本)

    0x01 fopen 函数 函数原型:FILE *fopen(const char *filename, const char *mode) 返回值为 FILE 类型 函数功能:使用给定的模式 mod ...

  4. 蓝桥杯--- 历届试题 大臣的旅费 (DFS & Vector)

    题目提交链接:http://lx.lanqiao.org/problem.page?gpid=T32 问题描述 很久以前,T王国空前繁荣.为了更好地管理国家,王国修建了大量的快速路,用于连接首都和王国 ...

  5. Pet(dfs+vector)

    Pet Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  6. 【PTA 天梯赛训练】词频统计(map+vector)

    请编写程序,对一段英文文本,统计其中所有不同单词的个数,以及词频最大的前10%的单词. 所谓“单词”,是指由不超过80个单词字符组成的连续字符串,但长度超过15的单词将只截取保留前15个单词字符.而合 ...

  7. J - Ananagrams(map+vector)

    Description Most crossword puzzle fans are used to anagrams--groups of words with the same letters i ...

  8. java学习第15天(Linklist Vector)

    根据集合的分类(上一天有说),首先接触的是ArrayList但是和Collection一样,他没有什么特殊的功能,直接跳过,然后是Vector. 一   Vector A:有特有功能 a:添加 pub ...

  9. hdu 4841 圆桌问题(STL vector)

    Problem Description 圆桌上围坐着2n个人.其中n个人是好人,另外n个人是坏人.如果从第一个人开始数数,数到第m个人,则立即处死该人:然后从被处死的人之后开始数数,再将数到的第m个人 ...

随机推荐

  1. AtCoder Grand Contest 020 D - Min Max Repetition

    q<=1000个询问,每次问a,b,c,d:f(a,b)表示含a个A,b个B的字符串中,连续A或连续B最小的串中,字典序最小的一个串,输出这个串的c到d位.a,b<=5e8,d-c+1&l ...

  2. Linux下C编程入门(1)

    Linux系统的介绍(以下以Manjaro最新版为例子): 一.系统的安装: 1.可以直接使用U盘做一个live usb的启动盘,在bios中设置从U盘启动即可拥有linux系统,如果是新式bios需 ...

  3. POJ2367 拓扑排序 裸题 板子题

    http://poj.org/problem?id=2367 队列版 #include <stdio.h> #include <math.h> #include <str ...

  4. 博弈论入门题 kiki's game

    Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his mind ...

  5. [bzoj3513][MUTC2013]idiots_FFT

    idiots bzoj-3513 MUTC-2013 题目大意:给定$n$根木棍,问随机选择三根能构成三角形的概率. 注释:$1\le n\le 3\cdot 10^5$,$1\le a_i\le 1 ...

  6. 基于Token的身份验证——JWT(转)

    本文转自:http://www.cnblogs.com/zjutzz/p/5790180.html 感谢作者 初次了解JWT,很基础,高手勿喷.基于Token的身份验证用来替代传统的cookie+se ...

  7. component and slot

    component and slot 使用: 1.component panel <article class="message"> <div class=&qu ...

  8. IOS开发UI篇--一个支持图文混排的ActionSheet

    一.简单介绍 UIActionSheet是IOS提供给我们开发人员的底部弹出菜单控件.一般用于菜单选择.操作确认.删除确认等功能.IOS官方提供的下面方式对UIActionView进行实例化: - ( ...

  9. socket 由浅入深系列------ 原理(一)

    来自:网络整理 个人觉得写一个网络应用程序没有是一件非常easy的事.其实,我们刚開始的时候总觉得的原则: 建立------>连接套接字------->接受一个连接---->发送数据 ...

  10. AE After Effect 如何替换和修改素材

    替换素材:如图所示,相框外的人是成双成对的,相框里面的却只有一个人,我们想要把这个素材替换成两个人的.我们鼠标放到视频预览框的任何一个元素上面底部都会提示这是什么素材.比如我放到一个人的上面,则该人物 ...