标签:一个 play bsp ++ pac lan cst std scan
输入N个数,M次查询。
每次查询给出一个数x。
要求:每次查询输出前x个数中第i小的数。(i为第i次查询)
你可以假设M <= N,Xi <= Xi+1 <= Xi+2 <= ……. <= Xm (Xm <= N).
1 7 4 3 1 -4 2 8 -1000 2 1 2 6 6
3 3 1 2
/** 分析:该题是,将前m个数升序排序,再输出 P[pos]的值 注意:不要将原数组直接进行排序 **/
C/C++代码实现:
#include <iostream> #include <algorithm> #include <cstring> #include <cmath> #include <cstdio> #include <stack> #include <queue> #include <map> using namespace std; int A[30005], B[30005]; int main () { int T; scanf ("%d", &T); while (T --) { int N, M, a; scanf ("%d%d", &N, &M); for (int i = 0; i < N; ++ i) scanf ("%d", &A[i]); for (int i = 1; i <= M; ++ i) { scanf ("%d", &a); for (int j = 0; j < a; ++ j) { B[j] = A[j]; } sort (B, B + a, less <int>()); printf ("%d\n", B[i - 1]); } } return 0; }
标签:一个 play bsp ++ pac lan cst std scan
原文地址:https://www.cnblogs.com/GetcharZp/p/8974733.html