https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1415

STL中sort和lower_bound(返回大于或者等于x的第一个位置)应用

 #include<bits/stdc++.h>
using namespace std;
int a[];
int main()
{
int n,q,cases=;
while(~scanf("%d %d",&n,&q),n+q)
{
cases++;
printf("CASE# %d:\n",cases);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
while(q--)
{
int temp;
scanf("%d",&temp);
int ans=lower_bound(a,a+n,temp)-a;
//printf("%d\n",ans);
if(a[ans]==temp)printf("%d found at %d\n",temp,ans+);//重点
else printf("%d not found\n",temp);
}
}
return ;
}

uvaoj 10474 - Where is the Marble?(sort+lower_bound)的更多相关文章

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

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

  2. 10474 - Where is the Marble?(模拟)

    传送门: UVa10474 - Where is the Marble? Raju and Meena love to play with Marbles. They have got a lot o ...

  3. UVa 10474 Where is the Marble

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

  4. STL入门--sort,lower_bound,upper_bound,binary_search及常见错误

    首先,先定义数组 int a[10]; 这是今天的主角. 这四个函数都是在数组上操作的 注意要包含头文件 #include<algorithm> sort: sort(a,a+10) 对十 ...

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

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

  6. UVA 10474 - Where is the Marble?--vector

    https://vjudge.net/problem/UVA-10474 https://blog.csdn.net/xiyaozhe/article/details/81081344 简单用法 so ...

  7. uva 10474 Where is the Marble?(简单题)

    我非常奇怪为什么要把它归类到回溯上,明明就是简单排序,查找就OK了.wa了两次,我还非常不解的怀疑了为什么会 wa,原来是我居然把要找的数字也排序了,当时仅仅是想着能快一点查找.所以就给他排序了,没考 ...

  8. 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 3(Sorting/Searching)

    第一题:340 - Master-Mind Hints UVA:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Item ...

  9. Volume 1. Sorting/Searching(uva)

    340 - Master-Mind Hints /*读了老半天才把题读懂,读懂了题输出格式没注意,结果re了两次. 题意:先给一串数字S,然后每次给出对应相同数目的的一串数字Si,然后优先统计Si和S ...

随机推荐

  1. Spring mvc实现ex导入导出

    依赖架包 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</arti ...

  2. mac os 隐藏文件夹的小技巧

    无论是谁,电脑里总有些不想让人看到的内容,或是私密日记,或是某播下载的奇怪东西,对于这些东西当然是不想被人看到的.怎么办呢? 有人说了几种方法: 1. 改名字: 2. 把文件夹做成加密DMG: 3. ...

  3. 跟我一起写 Makefile (Linux )

    1.昨天 在 Linux 下用  touch  指令 新建了一个  hello.c 并且使用 vim 编辑器 写了代码 ,使用 gcc 指令编译 最后运行 成功了 .具体方式如下: 在Linux 根目 ...

  4. 理解AndroidX

    理解AndroidX 刚刚看到自己加的一个Android群里有人问AndroidX,还是Google自己的,竟然没听说过,慌的一匹.赶紧去看了下官方文档和一些博客,对AndroidX有了如下理解 An ...

  5. grid 布局的使用

    grid 布局的使用 css 网格布局,是一种二维布局系统. 浏览器支持情况:老旧浏览器不支持, 概念: 网格容器.元素应用dispalay:grid,它是所有网格项的父元素. <div cla ...

  6. MAMP:MySQL wasn't able to start

    MAMP 我点击start server的时候 发现mysql服务器打不开 http://images.cnblogs.com/cnblogs_com/lwwen/1231721/o_11111111 ...

  7. Java中Date类型如何向前向后滚动时间,( 附工具类)

    Java中的Date类型向前向后滚动时间(附工具类) 废话不多说,先看工具类: import java.text.SimpleDateFormat; import java.util.Calendar ...

  8. html+css3 实现各种loading效果

    效果见下图 代码: 建议直接去本人github上浏览代码 https://github.com/wuliqiangqiang/loading <!DOCTYPE html> <htm ...

  9. 微信支付tp5.1集合

    多商户号微信支付 配置 自己改一改 逻辑 就好了! 写的菜 勿喷 extend下面 主要目录 多商户号 配置项 根据自己的需求更改 可能有一些地方存在BUG 自己调试一下 就OK了,别像一个麻瓜一样 ...

  10. angular2路由之routerLinkActive指令

    angular2的routerLinkActive指令在路由激活时添加样式class .red{  color: red;}    <a routerLink="/user/login ...