linshangyuan @ 2024-03-16 17:04:45
#include<bits/stdc++.h>
using namespace std;
int a[1001];
int n,m,tmp;
int find(int x)
{
int l=1,r=n;
while(l<r)
{
int mid=l+(r-l)/2;
if(a[mid]>=x) r=mid;
else l=mid+1;
}
if(a[l]==x) return l;
else return -1;
}
int main()
{
cin >> n >> m;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=0;i<m;i++){
cin>>tmp;
cout<<find(tmp)<<" ";
}
return 0;
}
by _Ayanami_Rei_ @ 2024-03-16 17:27:08
RE一般是数组开的不够大
你看题目中
by linshangyuan @ 2024-08-13 19:07:06
谢谢,已关注