UVA 10474 Where is the Marble
来源:互联网 发布:路桥专业淘宝拍照 编辑:程序博客网 时间:2024/06/15 16:37
这是一道较为简单的匹配问题,先用sort函数对输入的数组进行排序,在通过查找元素,找到目标元素所在位置并输出
#include <cstdio>#include <algorithm>using namespace std;const int maxn = 10000;int main(){ int n, q, x, a[maxn], kase = 0; while(scanf("%d%d", &n, &q) == 2 && n) { printf("CASE# %d:\n", ++kase); for(int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a+n);//包含于algorithm头文件里 while(q--) { scanf("%d", &x); int p = lower_bound(a, a+n, x) - a;//从a数组中,寻找第一个等于x的值 if(a[p] == x) printf("%d found at %d\n", x, p+1); else printf("%d not found\n", x); } } return 0;}
0 0
- 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?
- 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?
- uva - 10474 - Where is the Marble?
- uva 10474 - Where is the Marble
- protobuf V3 C# 中文机翻教程。
- Design Pattern - Structural Patterns - Decorator Pattern
- 海龟作图—用Python 绘图
- js比较日期格式大小 功能da1=da2返回真
- 实时数据库中的数据压缩技术
- UVA 10474 Where is the Marble
- WTL 解析json,借助jsoncpp库
- html基础
- Visual Studio 2015 添加WTL支持
- Hust oj 2013(Play Game 2)(博弈)
- Java垃圾收集机制
- xUtils更新到3.0后的基本使用规则
- Java Concurrent包源码学习和使用心得 之 LinkedBlockingQueue源码解读
- js正则替换指定的所有字符