wcx_is_god @ 2024-05-04 20:10:39
样例输出的是555,真的很神奇,废话少说,请看代码 ->
#include<bits/stdc++.h>
using namespace std;
int a[1000005],m,n,q,ans = 0;
int f(int q){
int l = 0,r = n,mid;
while(l<r){
mid = (l+r)/2;
if(a[mid] = q) return mid;
else if(a[mid] < q) l = mid+1;
else r = mid-1;
}
return -1;
}
int main(){
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",&q);
ans = f(q);
cout << ans << " ";
}
return 0;
}
by Jason_Ming @ 2024-05-04 20:15:20
《a[mid] = q
》
by Jason_Ming @ 2024-05-04 20:21:27
@WCX12312
by wcx_is_god @ 2024-05-07 16:04:22
3q,真的是6了,原来是这里