参考:ACM紫书 第五章 P108 【排序与检索】

下面的代码中有些 提示性输出,想Ac 需删除提示性输出语句,读者自行修改。

#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 10000; int main(void)
{
int n,q,numarr[maxn],i,x,p,Case=0;
while(scanf("%d%d",&n,&q)==2 && n)
{
printf("CASE# %d:\n",++Case);
for(i=0; i<n; i++)
{
scanf("%d",&numarr[i]);
}
sort(numarr,numarr+n);
while(q--)
{
scanf("%d",&x); printf("%d--%p\n",*numarr,numarr);
printf("%d--%p\n",*lower_bound(numarr,numarr+n,x),lower_bound(numarr,numarr+n,x)); p=lower_bound(numarr,numarr+n,x)- numarr;
printf("p = %d\n",p);
if(numarr[p]==x)printf("%d found at %d\n",x,p+1);
else printf("%d not found\n",x);
}
}
return 0;
}

  

大理石在哪?(Where is the Marble?,UVa 10474)的更多相关文章

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

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

  2. Where is the Marble UVA - 10474

     Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on th ...

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

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

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

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

  5. 【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 ...

  6. 大理石在哪里UVa 10474

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

  7. UVA 10474 大理石在哪 lower_bound

    题意:找输入的数在排完序之后的位置. 主要是lower_bound 函数的使用.它的作用是查找大于或者等于x的第一个位置. #include<cstdio> #include<alg ...

  8. UVa 10474 Where is the Marble

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

  9. uva 10474 Where is the Marble? 计数排序

    题目给出一系列数字,然后问哪个数字是从小到大排在第几的,重复出现算第一个. 数据范围为10000,不大,完全可以暴力,sort不会超时. 但是由于以前做比赛时也遇到这种题目,没注意看数据范围,然后暴力 ...

随机推荐

  1. c语言 动态数组

    C语言中,在声明数组时,必须明确告诉编译器数组的大小,之后编译器就会在内存中为该数组开辟固定大小的内存.有些时候,用户并不确定需要多大的内存,使用多大的数组,为了保险起见,有的用户采用定义一个大数组的 ...

  2. C语言 文件操作2--文件缓存的理解

    //文件缓存机制理解 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> void mai ...

  3. ajax读取文本内容(此处的txt文件和html文件处于同级目录)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <style&g ...

  4. 每日一SQL-善用DATEADD和DATEDIFF

    转自:http://www.dotblogs.com.tw/lastsecret/archive/2010/10/04/18097.aspx 上個星期去Tech-Day聽了幾場有趣的課,其中一堂是楊志 ...

  5. 2016科幻惊悚《第五波》HD720P.中英双字

    导演: J·布莱克森编剧: 苏珊娜·格兰特 / 阿齐瓦·高斯曼 / 杰夫·皮克纳 / 瑞克·杨西主演: 科洛·莫瑞兹 / 尼克·罗宾森 / 朗·里维斯顿 / 玛姬·丝弗 / 亚历克斯·罗伊 / 更多. ...

  6. Android 编程下 Touch 事件的分发和消费机制

    Android 中与 Touch 事件相关的方法包括:dispatchTouchEvent(MotionEvent ev).onInterceptTouchEvent(MotionEvent ev). ...

  7. Activiti系列: 如何给内置表单添加字段类型

     对于内置的表单,除了原来支持的几种数据类型(string, long, enum, date, boolean, collection)之外,还可以自定义数据类型,比如增加一个javascript数 ...

  8. [CareerCup] 4.3 Create Minimal Binary Search Tree 创建最小二叉搜索树

    4.3 Given a sorted (increasing order) array with unique integer elements, write an algorithm to crea ...

  9. 信息安全系统设计基础exp_5

    北京电子科技学院(BESTI) 实     验    报     告 课程:信息安全系统设计基础 班级:1353 姓名:郑伟.吴子怡 学号:20135322.20135313 指导教师: 娄嘉鹏 实验 ...

  10. 20145208 实验三 Java面向对象程序设计

    20145208 实验三 Java面向对象程序设计 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验步 ...