简简单单
2024-08-20 13:26:50
发布于:江苏
2阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int n, a[100001];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i ++)
scanf("%d", &a[i]);
int x;
scanf("%d", &x);
int L = 0, R = n + 1;
while (L + 1 < R) {
int M = (L + R) / 2;
if (a[M] < x)
L = M;
else
R = M;
}
if (R <= n && a[R] == x)
printf("%d\n", R);
else
printf("-1\n");
}
这里空空如也
有帮助,赞一个