提交时间:2024-04-10 13:49:41
运行 ID: 142869
#include<bits/stdc++.h> using namespace std; int n,a[10001],k; int main(){ cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; cin>>k; int l=1,r=n,mid; while(l<=r){ mid=(l+r)/2; if(a[mid]==k){ cout<<mid; return 0; } else if(a[mid]<k)l=mid+1; else r=mid-1; } cout<<-1; return 0; }