#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
int a[100000+5];
int m;
int text(int zz)
{
int low=1,high=m;
int hh;
while(low<=high)
{
hh=(low+high)/2;
if(zz==a[hh])
{
return 1;
}
else if(zz<a[hh])
{
high=hh-1;
}
else
{
low=hh+1;
}
}
return 0;
}
int main()
{
while(scanf("%d",&m)!=EOF)
{
for(int i=1; i<=m; i++)
{
scanf("%d",&a[i]);
}
stable_sort(a+1,a+m+1);
int zz;
scanf("%d",&zz);
if(text(zz))
{
cout<<"true"<<endl;
}
else
{
cout<<"false"<<endl;
}
}
return 0;
}
二分查找
最新推荐文章于 2022-02-16 14:31:27 发布