lower_bound最简单解法
2025-03-15 20:38:06
发布于:广东
2阅读
0回复
0点赞
灵机一动
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
long long n, s[110], x, ans;
int main(){
cin>>n;
for (int i=1; i<=n; i++){
cin>>s[i];
}
cin>>x;
ans = lower_bound(s+1, s+n+1, x) - s;
if (s[ans]!=x){
cout<<"-1";
} else{
cout<<ans;
}
return 0;
}
这里空空如也
有帮助,赞一个