H - Where is the Marble?(set+vector)
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)的更多相关文章
- C语言中.h和.c文件解析(很精彩)
C语言中.h和.c文件解析(很精彩) 简单的说其实要理解C文件与头文件(即.h)有什么不同之处,首先需要弄明白编译器的工作过程,一般说来编译器会做以下几个过程: 1.预处理阶段 2.词法与语法分析 ...
- 逆向 stdio.h 函数库 fseek 函数(调试版本)
0x01 fseek 函数 函数原型:int fseek(FILE *stream, long int offset, int whence) 函数功能:设置流 stream 的文件位置为给定的偏移 ...
- 逆向 stdio.h 函数库 fopen 函数(调试版本)
0x01 fopen 函数 函数原型:FILE *fopen(const char *filename, const char *mode) 返回值为 FILE 类型 函数功能:使用给定的模式 mod ...
- 蓝桥杯--- 历届试题 大臣的旅费 (DFS & Vector)
题目提交链接:http://lx.lanqiao.org/problem.page?gpid=T32 问题描述 很久以前,T王国空前繁荣.为了更好地管理国家,王国修建了大量的快速路,用于连接首都和王国 ...
- Pet(dfs+vector)
Pet Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- 【PTA 天梯赛训练】词频统计(map+vector)
请编写程序,对一段英文文本,统计其中所有不同单词的个数,以及词频最大的前10%的单词. 所谓“单词”,是指由不超过80个单词字符组成的连续字符串,但长度超过15的单词将只截取保留前15个单词字符.而合 ...
- J - Ananagrams(map+vector)
Description Most crossword puzzle fans are used to anagrams--groups of words with the same letters i ...
- java学习第15天(Linklist Vector)
根据集合的分类(上一天有说),首先接触的是ArrayList但是和Collection一样,他没有什么特殊的功能,直接跳过,然后是Vector. 一 Vector A:有特有功能 a:添加 pub ...
- hdu 4841 圆桌问题(STL vector)
Problem Description 圆桌上围坐着2n个人.其中n个人是好人,另外n个人是坏人.如果从第一个人开始数数,数到第m个人,则立即处死该人:然后从被处死的人之后开始数数,再将数到的第m个人 ...
随机推荐
- Thinkphp5.0 的Db操作
Thinkphp5.0 的Db操作 连接操作: <?php namespace app\index\controller; use think\Controller; use think\Db; ...
- UVA 140_Bandwidth
题意: 定义一个结点的带宽是其距离所有相连结点的最远距离,一个图的带宽是图中所有结点带宽的最小值.给出一个图中各个结点的相邻情况,要求写出一个结点的排列,使得其所构成的图带宽最小. 分析: 枚举全排列 ...
- 解决Spring MVC无法接收AJAX使用PUT与DELETE请求传输的内容
解决Spring MVC无法接收AJAX使用PUT与DELETE请求传输的内容 解决方案 在 Web.xml文件中 加入以下代码 <!--解决ajax Put与Del请求无法接收到传输的内容-- ...
- I/O---BufferedInputStream及相关类介绍
关于BufferedInputStream 是java提供的具有缓存作用的字节输入流.与之对应的还有BufferedOutStream 和 BufferedRead 和BufferedWriter 这 ...
- Spring基础入门(一)
一.Spring概念 1.什么是Spring Spring是一个开源框架,它由Rod Johnson创建.它是为了解决企业应用开发的复杂性而创建的.Spring使用基本的JavaBean来完成以前 ...
- MongoDB小结04 - update【$inc】
update方法很强大,它有两个参数,一是查询文档,用来找出需要更新的文档,另一个是修改器(modifier)文档,描述对找到的文档做哪些修改. 亮点 更新操作是原子的,若两个更新同时发生,先到达服务 ...
- import与require的区别
载入一个模块import() 与 require() 功能相同,但具有一定程度的自动化特性.假设我们有如下的目录结构:~~~app/app/classes/app/classes/MyClass.lu ...
- yarn-cli 显示文件目录
显示yarn bin文件夹的位置. yarn bin yarn bin将打印yarn将为您的软件包安装可执行文件的文件夹.一个可执行文件的例子可能是你已经为你的包定义的脚本,可以通过执行yarn ru ...
- PC_excel完毕一列英文小写变大写
原创作品,出自 "深蓝的blog" 博客.欢迎转载,转载时请务必注明出处.否则追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlong ...
- POJ 3342 Party at Hali-Bula (树形dp 树的最大独立集 判多解 好题)
Party at Hali-Bula Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5660 Accepted: 202 ...