Ball search (a) time limit: 3000 MS | memory limit: 65535 kb difficulty: 3
-
-
Description
-
A game is popular in a country. The game rule is: in a pile of balls, each ball has an integer number I (0 <= I <= 100000000), which can be repeated, A random integer K (0 <= k <= 100000100) is used to determine whether the ball number k is in this heap ("yes"; otherwise, "no "), answer the question first to win. One person wants to play this game, but he is very lazy. He hopes that you can help him win.
-
-
Input
-
-
The first row has two integers, m, n (0 <= n <= 100000,0 <= m <= 1000000); M indicates that there are m balls in the heap, N indicates that the game is played n times.
Next, enter m + n integers. The first m represents the number I of the M balls, and the last n represents the random integer k in each game.
-
-
Output
-
-
Output "yes" or "no"
-
-
Sample Input
-
-
6 423 34 46 768 343 3432 4 23 343
-
-
Sample output
-
-
Nonoyesyes
-
-
Train of Thought: first, store elements in an array, then sort the elements by fast sorting, and finally perform binary search.
-
-
# Include <stdio. h> # include <stdlib. h> int s [1000005]; int low, high; int CMP (const void * a, const void * B) // fast sorting {return (* (int *) a-* (int *) B);} int jisuan (INT X) // binary lookup {int mid; while (low <= high) {mid = (low + high) /2; If (s [Mid] = x) return 1; else if (s [Mid] <X) Low = Mid + 1; elsehigh = mid-1 ;} if (low> high) return 0;} int main () {int I, m, n, a; scanf ("% d", & M, & N ); for (I = 0; I <m; I ++) scanf ("% d", & S [I]); qsort (S, M, sizeof (INT ), CMP); // fast sorting while (n --) {LOW = 0; high = s-1; scanf ("% d", & A); If (jisuan () = 1) // bipartite printf ("Yes \ n"); elseprintf ("NO \ n") ;}return 0 ;}
-
-
nyoj 86 ball search (1)