【入门】二分查找

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

说明

请在一个有序递增数组中(不存在相同元素),采用二分查找,找出值x的位置,如果x在数组中不存在,请输出-1!

输入格式

第一行,一个整数n,代表数组元素个数(n <= 106

第二行,n个数,代表数组的n个递增元素(1<=数组元素值<=108

第三行,一个整数x,代表要查找的数(0<=x<=108

输出格式

x在数组中的位置,或者-1。

样例

10
1 3 5 7 9 11 13 15 17 19
3
2

提示

请尝试采用递归和非递归两种方式来实现二分查找

第七届SWPU-ACM老生预选赛

Not Attended
Status
Done
Rule
ACM/ICPC
Problem
187
Start at
2022-9-19 14:00
End at
2022-10-28 14:00
Duration
936 hour(s)
Host
Partic.
45