题意:现在有N个大理石,每个大历史上写了一个非负整数。首先把各数从小到大排序,然后回答Q个问题。每个问题问是否有一个大理石写着某个整数x,如果是,还要回答哪个大理石上写着x。排序后所有的大理石从上到下编号为1~N。
思路:排序+二分。
#include<bits/stdc++.h>
using namespace std;
const int maxn=10005;
int main()
{
int n,q,a[maxn],kase=0;
while(cin>>n>>q&&n&&q)
{
printf("CASE# %d:\n",++kase);
memset(a,0,sizeof(a));
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
int x;
while(q--)
{
cin>>x;
int p=lower_bound(a,a+n,x)-a;
if(a[p]==x)
{
printf("%d found at %d\n",x,p+1);
}
else
{
printf("%d not found\n",x);
}
}
}
return 0;
}