提交时间:2023-11-08 13:16:54
运行 ID: 109269
#include<bits/stdc++.h> using namespace std; int n,a[10001],s,ans; int find(int l,int r) { int mid=(l+r)/2; if(a[mid]>s) return find(l,mid-1); else if(a[mid]<s) return(mid+1,r); else return mid; } int main() { cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; cin>>s; ans=find(1,n); if(ans==0) cout<<-1; else cout<<ans; return 0; }