ProgramAlgTrain/20240919/CSP常考算法模板/二分查找_加速查询.cpp
2024-09-19 10:22:41 +08:00

39 lines
379 B
C++

#include <bits/stdc++.h>
using namespace std;
int a[11]={5, 13, 19, 21, 37, 56, 64, 75, 80, 88, 92};
int main()
{
int x;
cin>>x;
int l=0,r=10;
int ans;
while(l<=r)
{
int mid=(l+r)/2;
if(x==a[mid])
{
cout<<mid;
return 0;
}
if(x<a[mid])
{
r=mid-1;
}
else
{
ans=mid;
l=mid+1;
}
}
cout<<"Not found!";
return 0;
}
//5
//1 -2 3 1 -4