Description
Judge whether there are two integers A and B in the Set S, and the sum of them is integer x.
Input
An integer in the first row indicates the number of groups (multiple groups of data). For each group of data, the first row has two integers n (1 ≤ n ≤ 10000 ), M (1 ≤ m ≤ 100 ). The second row is the set of n different integers. The third row has m Integers to be verified.
Output
Output a line for each integer to be verified. If the set S contains two integers and the sum of the Integers to be verified, output "yes"; otherwise, output "no ".
Solution: this problem can be implemented using an array. The input number is considered as the subscript of the array, and all given numbers are marked as 1 in the array, that is, result [A [I] = 1; then, for each X, subtract a [I] to determine whether the remaining number is marked in the array. Considering that A and B are interchangeable, you only need to find half of the elements.
# Include <stdio. h> main () {int number, Te; int I, J, K, M; int number1, number2; int A [10000]; int result [100000]; int B; int flag; scanf ("% d", & number); For (TE = 1; te <= number; Te ++) {for (k = 0; k <100000; k ++) result [k] = 0; scanf ("% d", & number1, & number2); for (I = 1; I <= number1; I ++) {scanf ("% d", & A [I]); Result [A [I] = 1 ;}for (I = 1; I <= number2; I ++) {flag = 0; scanf ("% d", & B); For (j = 1; j <= number1/2; j ++) {If (result [B-A [J] = 1) Flag = 1; elsecontinue;} If (flag = 1) printf ("Yes \ n"); else printf ("NO \ n ");}}}