题意:找输入的数在排完序之后的位置。

主要是lower_bound 函数的使用。它的作用是查找大于或者等于x的第一个位置。

  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4.  
  5. const int maxn = ;
  6.  
  7. int main()
  8. {
  9. int n,q,x,a[maxn],kase = ;
  10. while(scanf("%d%d",&n,&q) == && n){
  11. printf("CASE# %d:\n",++kase);
  12. for(int i = ;i < n; i++) scanf("%d",&a[i]);
  13.  
  14. sort(a,a+n);
  15.  
  16. while(q--){
  17. scanf("%d",&x);
  18. int p = lower_bound(a,a+n,x) - a;
  19. if(a[p] == x) printf("%d found at %d\n",x,p+);
  20. else printf("%d not found\n",x);
  21. }
  22. }
  23. return ;
  24. }

UVA 10474 大理石在哪 lower_bound的更多相关文章

  1. UVA.10474 Where is the Marble ( 排序 二分查找 )

    UVA.10474 Where is the Marble ( 排序 二分查找 ) 题意分析 大水题一道.排序好找到第一个目标数字的位置,返回其下标即可.暴力可过,强行写了一发BS,发现错误百出.应了 ...

  2. 大理石在哪儿(Where is the Marble?,Uva 10474)

    现有N个大理石,每个大理石上写了一个非负整数.首先把各数从小到大排序,然后回 答Q个问题.每个问题问是否有一个大理石写着某个整数x,如果是,还要回答哪个大理石上 写着x.排序后的大理石从左到右编号为1 ...

  3. 大理石在哪里UVa 10474

    我自己写的代码 #include<iostream>#include<algorithm>using namespace std;int main(){    int N,a[ ...

  4. 大理石在哪?(Where is the Marble?,UVa 10474)

    参考:ACM紫书 第五章 P108 [排序与检索] 下面的代码中有些 提示性输出,想Ac 需删除提示性输出语句,读者自行修改. #include <cstdio> #include < ...

  5. 大理石在哪儿 (Where is the Marble?,UVa 10474)

    题目描述:算法竞赛入门经典例题5-1 #include <iostream> #include <algorithm> using namespace std; ; int m ...

  6. 【UVA - 10474 】Where is the Marble?(排序)

    Where is the Marble? Descriptions: Raju and Meena love to play with Marbles. They have got a lot of ...

  7. UVA 10474

    题意:给你一组数,再给几个数问是否在一组数中. 题很简单:STL入门. 没用到STL. #include<iostream> #include<cstdio> #include ...

  8. UVa 10474 Where is the Marble

    题意:给出一列数,先排序,再查找学习了sort函数,lower_bound函数sort:可以给任意对象排序(包括自己定义的)(前提是定义好了‘<’运算符)lower_bound:查找大于或者等于 ...

  9. 【例题5-1 UVA 10474 】Where is the Marble?

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 排序 用lower_bound找就可以了. ->lower_bound,如果里面所有的数字都比x小,那么它的返回值会越界! [ ...

随机推荐

  1. android DevicePolicyManager实现一键锁屏

    本文章一部分资料来源于网上 1.实现一键锁屏关键是DevicePolicyManager这个类,然后使用lockNow():方法. 2.DevicePolicyManager类,可以让你的做软件获得系 ...

  2. HQL 参数绑定、唯一结果、分页、投影总结(上)

    我们先总结一下HQL语句常用语法: from子句:; select子句:用于选取对象和属性; where子句:用于表达查询语句的限制条件; 使用表达式:一般用在where子句中; order by子句 ...

  3. 15 sql base line 工作机制

    <个人Configuration> 正常配置一下, 就OK了, 不用理了, oracle 11g 默认启动 发展: .从Oracle的发展角度来看,估计这种方法是Oracle发展和改进的方 ...

  4. Django1.9开发博客(10)- 全文搜索

    Django本身不提供全文检索的功能,但django-haystack为其提供了全文检索的框架. django-haystack能为Django提供whoosh,solr,Xapian和Elastic ...

  5. JQuery操作HTML文档

    一.JQuery选择元素 1.$("p").click(function(){$(this).hide();} 点击HTML页面的任何p元素都会隐藏该p元素 2.$("# ...

  6. 1.JavaScript面试

    1.1. 简要描述 JavaScript 的数据类型?   参考答案:   JavaScript 的数据类型可以分为原始类型和对象类型. 原始类型包括 string.number 和 boolean  ...

  7. 练习使用XRecyclerView,可上拉下拉刷新。

    package com.lixu.testxrecyclerview; import android.support.v7.app.AppCompatActivity; import android. ...

  8. 一个 11 行 Python 代码实现的神经网络

    一个 11 行 Python 代码实现的神经网络 2015/12/02 · 实践项目 · 15 评论· 神经网络 分享到:18 本文由 伯乐在线 - 耶鲁怕冷 翻译,Namco 校稿.未经许可,禁止转 ...

  9. 快消零售行业怎么用K2做开关店管理?

    提起迪卡侬,想到的便是它汇聚所有运动于同一个屋檐下的盛况.从来没有一家体育用品零售店可以像迪卡侬一样,涵盖几乎所有级别的运动产品.从入门级到最专业的运动产品,应有尽有,不仅产品质量有保证,价格也平易近 ...

  10. 超链接<a></a>

    1.<a href="#" target="_self原窗口-默/_blank新窗口/_top/_parent"></a> 绝对路径:f ...