Time Limit:3000MS     Memory Limit:0KB
Description
Download as PDF
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

题解:由于数据量只有10000,暴力求解即可。先进行排序,然后使用lower_bound()函数寻找位置即可。

以下是代码: 

#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <cstring>
#include <algorithm>
using namespace std;
int a[10005];
int main()
{
//freopen("1.in","r",stdin);
int N,Q,t,p;
int k=0;
while(scanf("%d%d",&N,&Q)!=EOF && (N || Q)){
for(int i=0;i<N;i++)
scanf("%d",&a[i]);
sort(a,a+N);//排序
printf("CASE# %d:\n",++k);
while(Q--){
scanf("%d",&t);
p = lower_bound(a,a+N,t)-a;//小于等于t的最初位置
if(a[p]==t){//存在,则输出
printf("%d found at %d\n",t,p+1);
}else printf("%d not found\n",t);
}
}
}

  

Winter-2-STL-C Where is the Marble? 解题报告及测试数据的更多相关文章

  1. UVa第五章STL应用 习题((解题报告))具体!

    例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...

  2. 《STL详解》解题报告

    看完发现文档缺页...... 3.5  菲波那契数 vector<int> v; v.push_back(); v.push_back(); ;i < ;++i) v.push_ba ...

  3. 转:详细解说 STL 排序(Sort)

    详细解说 STL 排序(Sort) 详细解说 STL 排序(Sort) 作者Winter 详细解说 STL 排序(Sort) 0 前言: STL,为什么你必须掌握 1 STL提供的Sort 算法 1. ...

  4. 详细解说 STL 排序(Sort)(转)

    作者Winter 详细解说 STL 排序(Sort) 0 前言: STL,为什么你必须掌握 1 STL提供的Sort 算法 1.1 所有sort算法介绍 1.2 sort 中的比较函数 1.3 sor ...

  5. c++ STL sort struct comp

    详细解说 STL 排序(Sort) http://www.cppblog.com/mzty/archive/2005/12/15/1770.html 详细解说 STL 排序(Sort) 作者Winte ...

  6. bjfu1299 stl使用

    题目超简单,我写解题报告是因为我的代码用了些STL,使代码很简洁. * * Author : ben */ #include <cstdio> #include <cstdlib&g ...

  7. Codeforces Round #268 (Div. 2) D. Two Sets [stl - set + 暴力]

    8161957                 2014-10-10 06:12:37     njczy2010     D - Two Sets             GNU C++     A ...

  8. DS实验题 融合软泥怪-1

    题目 思路 很容易想到第一种做法,用Huffman算法,从森林中找出两个值最小的节点,合并再加入森林,在这个过程中不断记录. 但是每一次需要sort一遍,将最小的两个值节点置于头两个节点,最坏情况下复 ...

  9. nyoj133_子序列_离散化_尺取法

    子序列 时间限制:3000 ms  |  内存限制:65535 KB 难度:5   描述 给定一个序列,请你求出该序列的一个连续的子序列,使原串中出现的所有元素皆在该子序列中出现过至少1次. 如2 8 ...

随机推荐

  1. hdu 2437(dfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2437 思路:只需用一个二维数组记录到达某点时路径长度mod k的最短路径长度,如果余数相同,就更新最小 ...

  2. servlet和jsp中间的交互

    jsp本质上也是一个servlet, 所有的jsp页面最终会编译成一个servlet 1. jsp访问servlet jsp访问servlet比较简单通过get, post的方式直接访问servlet ...

  3. Nuget包制作最佳解决方案

    https://www.cnblogs.com/drea/p/8418717.html 最近研究ABP框架,下载其全套源码,想“据为己有”,这样添加功能或者修改源码的话就非常方便了,否则搭建项目直接用 ...

  4. 使用cordova+Ionic+AngularJs进行Hybird App开发的环境搭建手冊

    一.所需工具 1,JDK:生成 2.安卓SDK开发环境 3,NodeJs:主要使用的还是npm 4,Python开发环境 5.VS 2012(2008,2015也能够,已亲測):安装这个主要是须要一些 ...

  5. WinForm------如何修改PanelControl控件背景色

    方法: 如何修改panelcontrol背景色 this.bottomPanel.BorderStyle = BorderStyles.NoBorder; this.bottomPanel.Appea ...

  6. IOS 开发之 -- 过滤掉字符串里面所有的非法字符 字典和json之间的互转

    比如一个字符串: NSString * hmutStr = @"(010)*(123)E6(234)**150-1111-^^-1234#" 很多时候,数据之间的传输,我们仅仅只想 ...

  7. 自定义控件_水平滑动的View 自定义属性

    保持饥饿,保持愚蠢,我们对待事情本来应该就是这样的 接下来我要写一个水平滑动的自写义,实现效果 水平滑动我们有很多种实现方法,recyceryView,HorizontalScrollView都可以, ...

  8. 【BZOJ2801】[Poi2012]Minimalist Security BFS

    [BZOJ2801][Poi2012]Minimalist Security Description 给出一个N个顶点.M条边的无向图,边(u,v)有权值w(u,v),顶点i也有权值p(i),并且对于 ...

  9. HDFS编程

    HDFS编程主要API Hadoop类 功能 org.apache.hadoop.fs.FileSystem 一个通用文件系统的抽象基类,可以被分布式文件系统继承.所有的可能使用Hadoop文件系统的 ...

  10. 170331、58到家MQ如何快速实现流量削峰填谷

    问:为什么会有本文? 答:上一篇文章<到底什么时候该使用MQ?>引起了广泛的讨论,有朋友回复说,MQ的还有一个典型应用场景是缓冲流量,削峰填谷,本文将简单介绍下,MQ要实现什么细节,才能缓 ...