1. Raju and Meena love to play with Marbles. They have got a lot of
  2. marbles with numbers written on them. At the beginning, Raju would
  3. place the marbles one after another in ascending order of the numbers
  4. written on them. Then Meena would ask Raju to find the first marble
  5. with a certain number. She would count ....... Raju gets one point
  6. for correct answer, and Meena gets the point if Raju fails. After some
  7. fixed number of trials the game ends and the player with maximum
  8. points wins. Today its your chance to play as Raju. Being the smart
  9. kid, youd be taking the favor of a computer. But dont underestimate
  10. Meena, she had written a program to keep track how much time youre
  11. taking to give all the answers. So now you have to write a program,
  12. which will help you in your role as Raju.
  13. Input
  14. There can be multiple test cases. Total no of test cases is less than . Each test case consists begins
  15. with integers: N the number of marbles and Q the number of queries Mina would make. The next
  16. N lines would contain the numbers written on the N marbles. These marble numbers will not come
  17. in any particular order. Following Q lines will have Q queries. Be assured, none of the input numbers
  18. are greater than and none of them are negative.
  19. Input is terminated by a test case where N = and Q = .
  20. Output
  21. For each test case output the serial number of the case.
  22. For each of the queries, print one line of output. The format of this line will depend upon whether
  23. or not the query number is written upon any of the marbles. The two different formats are described
  24. below:
  25. x found at y’, if the first marble with number x was found at position y. Positions are numbered
  26. , , . . . , N.
  27. x not found’, if the marble with number x is not present.
  28. Look at the output for sample input for details.
  29. Sample Input
  30.  
  31. Sample Output
  32. CASE# :
  33. found at
  34. CASE# :
  35. not found
  36. found at

    题目的 意思  大概就是       第一行  给你两个数字  第一个 代表了  第二行数字的个数   第二个 代表了 第三行数字的个数         将第二行的由小到大  排序之后        从第三行  中的 数字 和 第二行比较 如果 有相同的  就 打印  出  他排序之后   是第几个数字.

  1. // 关键是 第17行的 标准模板库 里面 的 一点东西 这也算是 第一次 有意识到 接触 标准模板库了吧.
  2. #include<cstdio>
  3. #include<algorithm>
  4. using namespace std;
  5. int main()
  6. {
  7. int q,n,a[],b,c,i,x,p,m,j,kase=;
  8. while(scanf("%d%d",&n,&m)==&&n)
  9. {
  10. printf("CASE# %d\n",++kase);
  11. for(i=;i<n;i++)
  12. scanf("%d",&a[i]);
  13. sort(a,a+n);
  14. while(m--)
  15. {
  16. scanf("%d",&x);
  17. p=lower_bound(a,a+n,x)-a; // 返回的 是 数组的 下标
  18. if(a[p]==x)
  19. printf("%d found at %d\n",x,p+);
  20. else
  21. printf("%d not found\n",x);
  22. }
  23. }
  24. return ;
  25. }

例题 5-1 STL的更多相关文章

  1. STL学习笔记(不定期更新)

    algorithm *1.sort() 用法:sort(数组名,名+长度(,cmp)); int cmp(T a,T b)//T是要排序的a,b的类型,也可以是结构体中任意成员变量 { return ...

  2. STL模板中的map的使用与例题

    最近的计分赛,记得自己的都只是过了两题.遇到了两次map,自己在寒假看了一点的map,只知道在字符串匹配的时候可以用的到.但是自己对map的使用还是不够熟练使用,这回在第一次和第二次的计分赛中都遇到可 ...

  3. 【C/C++】例题5-4 反片语/算法竞赛入门经典/C++与STL入门/映射:map

    本题是映射:map的例题. map:键值对. [题目] 输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一个单词. 在判断是否满足条件时,字母不分大小写,但在输出 ...

  4. 紫书 例题7-14 UVa 1602(搜索+STL+打表)

    这道题想了很久不知道怎么设置状态,怎么拓展,怎么判重, 最后看了这哥们的博客 终于明白了. https://blog.csdn.net/u014800748/article/details/47400 ...

  5. stl学习(三)crope的用法

    转载自http://blog.csdn.net/iamzky/article/details/38348653 曾经我不会写平衡树……于是在STL中乱翻……学到了pb_ds库中的SXBK的斐波那契堆. ...

  6. 【c++】标准模板库STL入门简介与常见用法

    一.STL简介 1.什么是STL STL(Standard Template Library)标准模板库,主要由容器.迭代器.算法.函数对象.内存分配器和适配器六大部分组成.STL已是标准C++的一部 ...

  7. stl 和并查集应用

    抱歉这么久才写出一篇文章,最近进度有点慢.这么慢是有原因的,我在想如何改进能让大家看系列文章的时候更方便一些,现在这个问题有了答案,在以后的推送中,我将尽量把例题和相关知识点在同一天推出,其次在代码分 ...

  8. 剑指offer例题分享--6

    前言:继续整理例题,快速做完这部分,然后继续用C++去刷数据结构和算法的题. 面试题28: 代码如下: #include<iostream> #include<stdio.h> ...

  9. STL语法——集合:set 安迪的第一个字典(Andy's First Dictionary,UVa 10815)

    Description Andy, , has a dream - he wants to produce his very own dictionary. This is not an easy t ...

随机推荐

  1. 《C语言程序设计(第四版)》阅读心得(四 文件操作)

    第10章  对文件的输入输出 函数名 调用形式 功能 fopen fopen(“a1”,”r”); 打开一个文件 fclose fclose( fp ); 关闭数据文件 fgetc fgetc( fp ...

  2. Bone Collector II(hdu 2639)

    题意:求01背包的第k最优值 输入:第一行为T,下面是T组数据,每组数据有n,m,k 代表n件物品,m容量,和题目要求的k,下一行是n个物品的价值,再一行是n个物品的体积 输出:T行答案 /* 类似于 ...

  3. 贝尔数--Codeforces908E. New Year and Entity Enumeration

    给n<=50个长度m<=1000的二进制数,记他们为集合T,求满足下面条件的集合S数:令$M=2^m-1$,1.$a \epsilon S \Rightarrow a \ \ xor \ ...

  4. 静态区间第k大(主席树)

    POJ 2104为例(主席树入门题) 思想: 可持久化线段树,也叫作函数式线段树,也叫主席树(高大上). 可持久化数据结构(Persistent data structure):利用函数式编程的思想使 ...

  5. CCNA参考链接

    http://www.cisco.com/c/en/us/support/docs/lan-switching/vtp/10558-21.html http://www.cisco.com/c/en/ ...

  6. [Algorithms] Insertion sort algorithm using TypeScript

    Insertion sort is a very intuitive algorithm as humans use this pattern naturally when sorting cards ...

  7. Qt实现Windows远程控制

    实现方式为server端+client. server端为一个进程.client为图形界面程序. client连接时设置server端的Ip地址,以及须要显示的长度和宽度(不能超过相应server端显 ...

  8. powerShell赋权限

    1.给网站赋权限 Set-SPUser –Identity “用户名” –AddPermissionLevel “参与讨论” –web “http://url” 2.给列表赋权限 $web = Get ...

  9. win7下 sublime text2操作快捷键 - leafu

    Ctrl+L            选择整行(按住-继续选择下行)                           Ctrl+KK          从光标处删除至行尾               ...

  10. mysql查看所有存储过程,函数,视图,触发器,表

    查询数据库中的存储过程和函数 方法一: select `name` from mysql.proc where db = 'your_db_name' and `type` = 'PROCEDURE' ...