标签:
题解:由于数据量只有10000,暴力求解即可。先进行排序,然后使用lower_bound()函数寻找位置即可。
以下是代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#include <iostream>#include <cstdio>#include <vector>#include <stack>#include <cstring>#include <algorithm>using namespace std;int a[10005];int main(){ //freopen("1.in","r",stdin); int N,Q,t,p; int k=0; while(scanf("%d%d",&N,&Q)!=EOF && (N || Q)){ for(int i=0;i<N;i++) scanf("%d",&a[i]); sort(a,a+N);//排序 printf("CASE# %d:\n",++k); while(Q--){ scanf("%d",&t); p = lower_bound(a,a+N,t)-a;//小于等于t的最初位置 if(a[p]==t){//存在,则输出 printf("%d found at %d\n",t,p+1); }else printf("%d not found\n",t); } }} |
Winter-2-STL-C Where is the Marble? 解题报告及测试数据
标签:
原文地址:http://www.cnblogs.com/gzdaijie/p/4298736.html