STL初步:大理石在哪儿?
来源:互联网 发布:多维数据可视化 编辑:程序博客网 时间:2024/04/28 06:49
uva 10474
现有N个大理石,每个大理石上写了一个非负整数。首先把各数从小到大排序,然后回答Q个问题。每个问题问是否有一个大理石写着某个整数x,如果是,还要回答哪个大理石上写着x。排序后的大理石从左到右编号为1~N。(样例中,为了节约篇幅,所有大理石上的数合并到一行,所有问题也合并到一行。)
样例输入:
4 1
2 3 5 1
5
5 2
1 3 3 3 1
2 3
样例输出:
CASE# 1:
5 found at 4
CASE# 2:
2 not found
3 found at 3
提示:sort函数与lower_bound函数结合完成
注:codeblocks测试数据通过
#include<iostream>#include<algorithm>using namespace std;const int maxn=10000;int main(){ int n,m,a[maxn],b[maxn],cases=1; while(cin>>n>>m) { for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=m;i++) cin>>b[i]; cout<<"CASE# "<<cases<<":"<<endl; cases++; sort(a+1,a+n+1); for(int i=1;i<=m;i++) { int p=lower_bound(a+1,a+n+1,b[i])-a;//注意·此处 if(a[p]==b[i]) cout<<b[i]<<" found at "<<p<<endl; else cout<<b[i]<<" not found"<<endl; } } return 0;}
0 0
- STL初步:大理石在哪儿?
- 大理石在哪儿?(Stl lower_bound用法)
- 大理石在哪儿
- UVa 10474 大理石在哪儿
- C++之大理石在哪儿?
- 例题:大理石在哪儿(UVa 10474)
- 算法入门经典:大理石在哪儿
- uva10474大理石在哪儿where is the marble?
- 例题5-1 大理石在哪儿 UVa10474
- 大理石在哪儿 where is the Marble? lower_bound()
- 大理石在哪儿 (排序和查找) UVA
- 大理石在哪儿 where is the Marble?
- UVa 10474 Where is the Marble?(大理石在哪儿)
- 大理石在哪儿(UVa 10474)(排序与检索)
- 10474 - 大理石在哪儿Where is the Marble?(排序+检索)
- uva 10474 Where is the Marble?(大理石在哪儿)
- 大理石在哪儿(Where is the marble?,UVa 10474)
- 大理石
- 服务器代码是正确的,但页面却一直加载以前代码
- 三个实例搞定MATLAb二维曲线图(绘制图像)
- LaTex格式论文编写环境搭建(TexLive+WinEdt+SumatraPDF)
- 数据库的迁移
- 【转载】前端常见算法的JS实现
- STL初步:大理石在哪儿?
- 每天一道算法题(2)——求整数的2进制表示中1的个数
- poj2891 Strange Way to Express Integers
- SharedPreferences封装类
- kafka容灾机制
- 大型网站技术架构-第1篇 概述
- Zookeeper解决分布式锁问题
- 2012年第三届蓝桥杯C/C++高职组真题补充训练(2017.3.9)
- java实现死锁