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. 跟着大神学Mongo,Mongodb主从复制本机简单操作总结

    原文链接:http://www.cnblogs.com/huangxincheng/archive/2012/03/04/2379755.html 本机安装MongoDB不在介绍,本文Mongo小菜鸟 ...

  2. Ajax实例二:取得新内容

    Ajax实例二:取得新内容 通过点击pre和next按钮,从服务器取得最新内容. HTML代码 <div id="slide">图片显示区</div> &l ...

  3. Comparable 接口的使用

    //学生类 package test; public class Student implements Comparable<Student>{ private int age; priv ...

  4. zabbix安装(网络)

    https://www.zabbix.com/documentation/3.4/zh/manual/quickstart/login   zabbix安装官网 https://www.zabbix. ...

  5. SpringMVC使用校验validator校验对象属性

    1.pom.xm添加依赖 <dependency> <groupId>javax.validation</groupId> <artifactId>va ...

  6. css圆角和阴影兼容问题(ie7,ie8)

    <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...

  7. POJ 1949 Chores (很难想到的dp)

    传送门: http://poj.org/problem?id=1949 Chores Time Limit: 3000MS   Memory Limit: 30000K Total Submissio ...

  8. jquery删除当前行

    <tr><td><input type='hidden' name='annex' value="+rs+"><a href='javas ...

  9. Unity 游戏框架搭建 (二十一) 使用对象池时的一些细节

    上篇文章使用SafeObjectPool实现了一个简单的Msg类.代码如下: class Msg : IPoolAble,IPoolType { #region IPoolAble 实现 public ...

  10. CF1066A Vova and Train(模拟)

    大水题... 题目要求你求能看到的灯笼数,我们可以分为3部分 总共的灯笼数——————1 在 l 左面的灯笼数(不包括lll)——————2 在 r 左面的灯笼数(包括rrr)——————3 我们知道 ...