#include <bits/stdc++.h>
using namespace std;
int main() {
int n,k,i,j,a[10000]={0};
cin>>n>>k;
for(i=1;i<=n;i++)cin>>a[i];
int s=1;
int t=n;
while(s<=t){//计算中间位置
if(a[t]==k){
cout<<t;//找到目标返回下标
break;
t=(t+e)/2;
}
else if (k>a[t] )
s=t+1;//目标在右半部分
else
t=t-1;//目标在左半部分
}
if(s>t){cout<<-1;}
return 0;
}
( ) |