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

参考: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)的更多相关文章
- 大理石在哪儿 (Where is the Marble?,UVa 10474)
题目描述:算法竞赛入门经典例题5-1 #include <iostream> #include <algorithm> using namespace std; ; int m ...
- 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 ...
- UVA.10474 Where is the Marble ( 排序 二分查找 )
UVA.10474 Where is the Marble ( 排序 二分查找 ) 题意分析 大水题一道.排序好找到第一个目标数字的位置,返回其下标即可.暴力可过,强行写了一发BS,发现错误百出.应了 ...
- 大理石在哪儿(Where is the Marble?,Uva 10474)
现有N个大理石,每个大理石上写了一个非负整数.首先把各数从小到大排序,然后回 答Q个问题.每个问题问是否有一个大理石写着某个整数x,如果是,还要回答哪个大理石上 写着x.排序后的大理石从左到右编号为1 ...
- 【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 ...
- 大理石在哪里UVa 10474
我自己写的代码 #include<iostream>#include<algorithm>using namespace std;int main(){ int N,a[ ...
- UVA 10474 大理石在哪 lower_bound
题意:找输入的数在排完序之后的位置. 主要是lower_bound 函数的使用.它的作用是查找大于或者等于x的第一个位置. #include<cstdio> #include<alg ...
- UVa 10474 Where is the Marble
题意:给出一列数,先排序,再查找学习了sort函数,lower_bound函数sort:可以给任意对象排序(包括自己定义的)(前提是定义好了‘<’运算符)lower_bound:查找大于或者等于 ...
- uva 10474 Where is the Marble? 计数排序
题目给出一系列数字,然后问哪个数字是从小到大排在第几的,重复出现算第一个. 数据范围为10000,不大,完全可以暴力,sort不会超时. 但是由于以前做比赛时也遇到这种题目,没注意看数据范围,然后暴力 ...
随机推荐
- GeoServer 常见问题总结
Geoserver安装环境 Geoserver在部署发布服务时,经常会遇到如下问题,现总结如下: 1.忘记了GeoServer Web Admin Page的登陆用户名和密码怎么办? 存储位置:C:\ ...
- 淘宝SKU组合查询算法实现
淘宝SKU组合查询算法实现 2015-11-14 16:18 1140人阅读 评论(0) 收藏 举报 分类: JavaScript(14) 目录(?)[+] 前端有多少事情可以做,能做到多 ...
- Android调用蓝牙打印机
首先需要一个jar包,bluesdk,请自行百度. 具体排版样式跟网络打印机打印排版样式实现一样,这里不多叙述,只贴一个实现方法代码.蓝牙打印机使用前需要先跟手机配对,可以保存在本地,记录下地址,这里 ...
- 浪潮之巅——IT那点事之二—蓝色巨人IBM
蓝色巨人IBM的全称是国际商用机器公司(International Business Machines Corporation),纵观IBM的发展历史,可以看出IBM与机器结缘,以商用为主的发展策略. ...
- MVC5 + EF6 + Bootstrap3 (8) HtmlHelper用法大全(上)
文章来源:Slark.NET-博客园 http://www.cnblogs.com/slark/p/mvc5-ef6-bs3-get-started-httphelper-part1.html 上一节 ...
- 用Canvas玩3D:点-线-面
声明:本文为原创文章,如需转载,请注明来源WAxes,谢谢! 玩Canvas玩了有两三个礼拜了,平面的东西玩来玩去也就那样,所以就开始折腾3D了. 因为Canvas画布终究还是平面的,所以要有3D就得 ...
- Git.Framework 框架随手记--ORM查询数据集合 一
本文记录Git.Framework之ORM中最为浓墨重彩的一篇,查询集合.根据自己做的项目统计这个是使用频率最高的一个. 一. 查询集合方法简介 (1)List<T> GetList(); ...
- java定时器的使用(Timer)
1.在应用开发中,经常需要一些周期性的操作,比如每5分钟执行某一操作等. 对于这样的操作最方便.高效的实现方式就是使用java.util.Timer工具类. private java.util.Tim ...
- new-nav-html
<header id="masthead" class="masthead" role="banner"> <h1 cla ...
- 学习笔记-动态树Link-Cut-Tree
--少年你有梦想吗? --少年你听说过安利吗? 安利一个集训队讲解:http://wenku.baidu.com/view/75906f160b4e767f5acfcedb 关于动态树问题,有多种方法 ...