大理石在哪儿 where is the Marble?
来源:互联网 发布:淘宝货到付款先发货 编辑:程序博客网 时间:2024/04/30 13:55
#include <iostream>#include <algorithm>using namespace std;main(){int n, q, x, a[10000], k = 0;while(cin >> n >> q){cout << "CASE#" << k << ":" << endl;k++;for(int i = 0; i < n; i++){cin >> a[i];}sort(a, a+n);while(q--){cin >> x;int p = lower_bound(a, a+n, x) - a; //在已知数组a中寻找xif(a[p] == x)cout << x << " found at " << p << endl;elsecout << x << " not found" << endl;} }}
题目
现有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
阅读全文
0 0
- uva10474大理石在哪儿where is the marble?
- 大理石在哪儿 where is the Marble? lower_bound()
- 大理石在哪儿 where is the Marble?
- UVa 10474 Where is the Marble?(大理石在哪儿)
- 10474 - 大理石在哪儿Where is the Marble?(排序+检索)
- uva 10474 Where is the Marble?(大理石在哪儿)
- 大理石在哪儿(Where is the marble?,UVa 10474)
- 《算法竞赛入门经典2ndEdition 》例题5-1 大理石在哪儿(Where is the marble?, Uva10474)
- 大理石在哪(Where is the Marble?, uva 10474)
- Where is the Marble
- Where is the Marble?
- Where is The Marble
- Where is the Marble?
- Where is the Marble?
- Where is the Marble?
- Where is the Marble?
- Where is the Marble?
- Where is the Marble?
- curses库(LINUX/UNIX图形函数库)
- maven管理java项目
- 初识大数据
- 使 32 位程序使用大于 2GB 的内存
- Spring JDBC 示例
- 大理石在哪儿 where is the Marble?
- 38. Count and Say
- CSS中的content属性
- 卷积神经网络——ResNet
- spring安装 使用 教程
- Linux中select IO复用机制
- Maximum Subarray (算法分析week2)
- #正念奇迹#ZQ0008《人类简史:从动物到上帝》
- 如何向整个 Git 仓库补提交一个文件