#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int a[N];
int n;
int ts(int x)
{
int l = 0,r = n - 1;
while(l <= r)
{
int L = (r - l) / 3 + l,R = 2 * (r - l) / 3 + l;
if(x < a[L])
{
r = L - 1;
}
else if(x == a[L])return L;
else if(x > a[L] && x < a[R])
{
l = L + 1;r = R - 1;
}
else if(x == a[R])return R;
else if(x > a[R])
{
l = R + 1;
}
}
}
int main()
{
cin >> n;
for(int i = 0;i < n;i++)scanf("%d",a + i);
int x;
cin >> x;
int ans = ts(x);
if(a[ans] == x)
cout << ts(x);
else cout << -1;
return 0;
}
实数三分
最新推荐文章于 2024-04-28 21:22:45 发布