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. 启动nmon报错while load libncurses.so.5 can not open shared(bit64)

    yum install ncurses-devel.i686 也有可能是软件包本身有问题,换一个try

  2. 【代码备份】原图降采样后进行NLM滤波

    文件路径: 滤波算法main.m: %% 测试函数 %NLM滤波及滤波与 clc,clear all,close all; ima_ori=double(imread('F:\Users\****n\ ...

  3. React Native开发技术

    http://www.lcode.org/react-native-week-issue22/

  4. Struts2_day01--导入源文件_Struts2的执行过程_查看源代码

    导入源文件 选中按ctrl + shift + t进入 Struts2执行过程 画图分析过程 过滤器在服务器启动时创建,servlet在第一次访问时创建 查看源代码 public class Stru ...

  5. 《C++ Primer Plus》第2章 开始学习C++ 学习笔记

    C++程序由一个或多个被称为函数的模块组成.程序从main()函数(全部小写)开始执行,因此该函数必不可少.函数由函数头和函数体组成.函数头指出函数的返回值(如果有的话)的类型和函数期望通过参数传递给 ...

  6. 【NGUI】Unity3D UIGrid 排序、动态加载与销毁

    本帖最后由 Lucifer_H 于 2014-10-31 09:39 编辑 做 UIGrid 的动态加载是做游戏的装备列表时用到的,装备信息都是从后台发过来的,具体加载的代码如下: [C#] 纯文本查 ...

  7. windows安装oracle11g第二部

    Oracle 11g数据库安装及配置 安装Oracle数据库: 1)压缩包解压,双击运行win64_11gR2_database\database\setup.exe 2)输入电子邮件,点击“下一步” ...

  8. 【BZOJ1135】[POI2009]Lyz 线段树

    [BZOJ1135][POI2009]Lyz Description 初始时滑冰俱乐部有1到n号的溜冰鞋各k双.已知x号脚的人可以穿x到x+d的溜冰鞋. 有m次操作,每次包含两个数ri,xi代表来了x ...

  9. springmvc常用注解标签详解(转载)

    1.@Controller 在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层处理之后封装成一个Model ...

  10. json学习之JSONArray的应用(转载)

    从json数组中得到相应java数组,如果要获取java数组中的元素,只需要遍历该数组. 1 /** 2 * 从json数组中得到相应java数组 3 * JSONArray下的toArray()方法 ...