Home > Back-end >  Binary search
Binary search

Time:04-03

7-3 binary search (binary search)
Description
Known a n elements from small to large, arrangement of integer sequences in a sequence of data is not repeat, now you're looking for a given value is the key, the location of the output key appear in this sequence,

In sequence in,2,3,5,8,9,12,21,37,49,55,613 [1], for example: find the result of 5, 4 found, said position is 4 (4 digits).

Enter
The first line contains a positive integer k, said k group test data, 1 & lt;=k & lt;=100, followed by k set of data,

For each set of data, the first line contains a two integers, n and key, said the group data integer number of elements in the sequence of n and to find the value of the key, (1 & lt;=n
=1000)
Then the line contains n from small to large, ranked integer, in turn, each element of the given sequence, the adjacent two integers separated by a space,

The absolute value of all elements in the title and the key is not more than 10000,

O
For each set of data, if the sequence of key, appear for the first time the output key position; Otherwise the output 1,

Each output a line alone,

The sample input
3
5 3
2, 3, 5 6 7
4, 5
1 2 3 4
1 1
1
Sample output
2
1
1

CodePudding user response:

The input sample can show?