算典05_例题_01_UVA-10474
来源:互联网 发布:清理恶意软件 编辑:程序博客网 时间:2024/06/06 04:01
Where is the Marble
题意
输入一组整数,排序之后找某数在数组中的位置
题解
水题。这一章主要是练习STL的用法,这题算是敲门砖。用sort排序,用lower_bound()查找即可
#include <iostream>#include <cstdio>#include <queue>#include <cstring>#include <algorithm>#include <cmath>using namespace std;const int maxn = 1e5 + 5;const int INF = (1<<31)-1;#define met(a, b) memset(a, b, sizeof(a));#define IN freopen("in.txt", "r", stdin);typedef long long LL;int n, q, a[maxn], b;int main(){ #ifdef _LOCAL IN; #endif // _LOCAL int kase = 0; while(scanf("%d%d", &n, &q) == 2) { if(!n && !q) break; for(int i = 0; i < n; ++i) scanf("%d", &a[i]); sort(a, a+n); printf("CASE# %d:\n", ++kase); while(q--) { scanf("%d", &b); int ans = lower_bound(a, a+n, b) - a; if(ans < n && a[ans] == b) printf("%d found at %d\n", b, ans+1); else printf("%d not found\n", b); } } return 0;}
0 0
- 算典05_例题_01_UVA-10474
- 算典03_例题_01_Uva-272
- 算典04_例题_01_UVA-1339
- 算典03_习题_01_Uva-1585
- 算典04_习题_01_UVA-1589
- 算典05_例题_02_UVA-101
- 算典05_例题_03_UVA-10815
- 算典05_例题_04_UVA-156
- 算典05_例题_05_UVA-12096
- 算典05_例题_06_UVA-540
- 算典05_例题_07_UVA-136
- 算典05_例题_08_UVA-400
- 算典05_例题_09_UVA-1592
- 算典05_例题_10_UVA-207
- 算典05_例题_11_UVA-814
- 算典05_例题_12_UVA-221
- 算典03_例题_02_Poj-2538
- 算典03_例题_03_HDU-1318
- 你真的了解volatile关键字吗?深入解析java并发与volatile
- Haskell快排代码
- HandlerThread用法
- MongoDB基本管理命令
- 第一个OpenGL出现无法识别glGenVertexArrays问题
- 算典05_例题_01_UVA-10474
- java多线程编程核心技术6-单例模式与多线程
- BMP文件读写以及RGB与YUV转换
- [李景山php]每天laravel[027]-laravel 基础知识 --- 请求
- 大白话系列之C#委托与事件讲解(三)
- 如何在CakePHP中使用Ajax请求
- 蓝桥杯 算法训练 最大最小公倍数
- python变量和输出
- 简单优先队列实现-基于最小堆