UVA 10474 大理石在哪 lower_bound
题意:找输入的数在排完序之后的位置。
主要是lower_bound 函数的使用。它的作用是查找大于或者等于x的第一个位置。
#include<cstdio>
#include<algorithm>
using namespace std; const int maxn = ; int main()
{
int n,q,x,a[maxn],kase = ;
while(scanf("%d%d",&n,&q) == && n){
printf("CASE# %d:\n",++kase);
for(int i = ;i < n; i++) scanf("%d",&a[i]); sort(a,a+n); while(q--){
scanf("%d",&x);
int p = lower_bound(a,a+n,x) - a;
if(a[p] == x) printf("%d found at %d\n",x,p+);
else printf("%d not found\n",x);
}
}
return ;
}
UVA 10474 大理石在哪 lower_bound的更多相关文章
- 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
我自己写的代码 #include<iostream>#include<algorithm>using namespace std;int main(){ int N,a[ ...
- 大理石在哪?(Where is the Marble?,UVa 10474)
参考:ACM紫书 第五章 P108 [排序与检索] 下面的代码中有些 提示性输出,想Ac 需删除提示性输出语句,读者自行修改. #include <cstdio> #include < ...
- 大理石在哪儿 (Where is the Marble?,UVa 10474)
题目描述:算法竞赛入门经典例题5-1 #include <iostream> #include <algorithm> using namespace std; ; int m ...
- 【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
题意:给你一组数,再给几个数问是否在一组数中. 题很简单:STL入门. 没用到STL. #include<iostream> #include<cstdio> #include ...
- UVa 10474 Where is the Marble
题意:给出一列数,先排序,再查找学习了sort函数,lower_bound函数sort:可以给任意对象排序(包括自己定义的)(前提是定义好了‘<’运算符)lower_bound:查找大于或者等于 ...
- 【例题5-1 UVA 10474 】Where is the Marble?
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 排序 用lower_bound找就可以了. ->lower_bound,如果里面所有的数字都比x小,那么它的返回值会越界! [ ...
随机推荐
- Extjs关于alert显示不出—异步问题
对应extjs提示框不能正常显示,而使用js的本身提示框可以正常,但由于样式不统一,不是 好的解决方法. 解决该问题,要了解extjs异步原理. ext的提示框都是异步的,非阻塞模式的,浏览器js的提 ...
- Git学习(4)基本操作
1.版本提交 首先,接着上个Git学习(3)继续 我们先修改test.txt文本内容,增加一些信息进去,然后保存: Add a new data 第一步:运行命令 git status 命令查看文件是 ...
- angularJS学习笔记之——搭建学习环境
学习AngularJS已经好几天了,从今天开始学习AngularJS环境搭建. 无论是Mac.Linux或Windows环境中,您均可遵循本教程学习编程. 第一步:安装Git Git是什么呢? Git ...
- springMVC的两种下载方式
1:通过httpServletResponse对象实现下载,觉得LOW的自行跳过 2:有人觉得既然使用的是MVC就要使用spring的方式
- Unsupported major.minor version 51.0解决
http://blog.csdn.net/justdb/article/details/7850212 解决:项目------>右键------>属性------>Java Comp ...
- org/objectweb/asm/Type异常解决办法
关于java.lang.NoClassDefFoundError: org/objectweb/asm/Type 调试SPRING MVC(或者整合SSH)的时候遇到了org/objectweb/as ...
- UNIX 逐字符输入
//终端驱动处于普通胡一次一字符模式 system("stty raw"); //终端驱动处于普通胡一次一行模式 system("stty cooked");
- 解决Centos7安装后无法联网的问题
1.进入目录/etc/sysconfig/network-scripts/ $ cd /etc/sysconfig/network-scripts/ 2.找到编辑ifcfg-enoxxxx文件,后面的 ...
- iptables基本规则
注意:iptables只能被拥有超级权限的用户设置. 重启 清空 iptables 规则:在终端输入: iptables -F iptables -X iptables -t nat -F i ...
- 设计模式之二:MVC
模型(Model) 视图(View) 控制器(Controller) (MVC) 是 Cocoa 中的一种行为模块,并且也是所有 Cocoa 设计模式中使用最多的.在程序中按照它们的角色来分类这些对象 ...