提交时间:2023-11-08 13:26:00
运行 ID: 109306
#include<bits/stdc++.h> using namespace std; long long n,a[1000001],x,middle,low,high; int bin(long long low,long long high) { if(low>high) return 0; else { middle=(low+high)/2; if(x==a[middle]) return 1; else if(x<a[middle]) { high=middle-1; bin(low,high); } else if(x>a[middle]) { low=middle+1; bin(low,high); } } } int main() { cin>>n; for(int i=0;i<n;i++) cin>>a[i]; cin>>x; low=0,high=n-1; bin(low,high); if(bin(low,high)==1) cout<<"YES"; else cout<<"NO"; return 0; }