标签:clu span 二分查找 for int 查找 main lse using
#include<bits/stdc++.h> using namespace std; int num[100]; int n; int ans; int main() { cin>>n; for(int i=1;i<=n;i++) { cin>>num[i]; } int goal; cin>>goal; int l=0; int r=n; while(l<=r) { int mid=(l+r)/2; if(num[mid]==goal) { ans=mid; break; } else if(num[mid]>goal) r=mid; else l=mid+1; } cout<<ans<<endl; }
标签:clu span 二分查找 for int 查找 main lse using
原文地址:https://www.cnblogs.com/KyleDeng/p/9595196.html