UVA - 10474 Where is the Marble?(STL,水)
来源:互联网 发布:python-kafka-logging 编辑:程序博客网 时间:2024/05/17 08:13
UVa 10474 Where is the Marble?(大理石在哪儿)
UVa题目链接
题目名称:大理石在哪
题目描述:
现有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
#include<iostream>#include<algorithm>#include<cstdio>using namespace std;const int MAXN = 10005;int a[MAXN];int main(){int n, q;int cas = 1;while (scanf("%d%d", &n, &q) != EOF&&n){for (int i = 0; i < n; i++)cin>>a[i];sort(a, a + n);cout << "CASE# " << cas << ':' << endl;cas++;int x;while (q--){cin >> x;int p = lower_bound(a, a + n, x) - a; //lower_bound函数返回大于或者等于x的第一个位置if (a[p] == x) cout <<x <<" found at "<<p + 1 << endl;else cout << x << " not found" << endl;}}}
0 0
- UVA - 10474 Where is the Marble?(STL,水)
- UVA 10474 Where is the Marble? (STL)
- UVa - 10474 Where is the Marble?(STL)
- uva 10474 Where is the Marble?(二分STL)
- UVA 10474:Where is the Marble?(STL初步)
- UVA 10474 Where is the Marble(stl,sort)
- where is the marble?(uva 10474)
- UVA 10474 Where is the Marble? 暴力|STL
- UVA 10474 Where is the Marble? (STL最简单运用)
- UVa 10474Where is the Marble STL 模板练习
- UVa 10474 Where is the Marble?
- Uva 10474 Where is the Marble?
- uva 10474 Where is the Marble?
- UVA 10474 Where is the Marble?
- UVA 10474 - Where is the Marble
- uva-10474 - Where is the Marble?
- uva 10474 - Where is the Marble?
- UVA 10474 - Where is the Marble?
- 是否是对方感到反感对发生的发顺丰斯蒂芬森
- win64位安装Oracle_11gR2数据库+PL\SQL Developer
- Linux练习题1
- osgearth mac/linux 下 cmake 编译安装
- 家政服务管理系统
- UVA - 10474 Where is the Marble?(STL,水)
- LeetCode - Recover Binary Search Tree
- C/C++_地址,存储区
- arcgis10.3安装方法说明
- Java数组技巧
- java数组的最大长度是多少?
- sqlite 简单使用
- 浮点数和十六进制之间的相互转换
- UVA - 101 The Blocks Problem(STL,模拟)