Can you find it?
Time limit:10000/3000 MS (java/others) Memory limit:32768/10000 K (java/others)
Total submission (s): 17036 Accepted Submission (s): 4337
Problem descriptiongive you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate if you can find the three numbers Ai, Bj, Ck, which satisfy the formula Ai+bj+ck = X.
Inputthere is many cases. Every data case was described as followed:in the first line there be three integers L, N, M, in the second line there was L integers represent the sequence A, in the third line there is N integers represent the sequences B, in the Forth line There is M integers represent the sequence C. The fifth line there was an integer s represents there was s integers X to be calculated. 1<=l, N, m<=500, 1<=s<=1000. All the integers is 32-integers.
Outputfor each case, firstly you has to print the case number as the form ' case D: ', then for the S queries, you Calculat E If the formula can be satisfied or not. If Satisfied, you print "YES", otherwise print "NO".
Sample INPUT3 3 31 2 31 2 31 2 331410
Sample outputcase 1:noyesno Test instructions: give you three groups of numbers, the number of each group is L N m and give you the number of S X to determine whether you can find a number from the three sets of numbers to make Ai+bj+ck = X. Solution: Violence must time out, so to use two points, the number of three groups of any two groups into the array str[], and then to each X to traverse 1, the test data is too weak, and such a set of test data is a hole, a lot of incorrect situation can draw the correct answer 2, the output format good pit, I thought it was a continuous output no yes No all the time I didn't think it was to lose a number of a result 3, be sure to pay attention to str[] array sorting (the condition of binary search is ordered series)
#include <stdio.h> #include <string.h> #include <algorithm>using namespace std; #define MAX 1100bool CMP (int a,int b) {return a<b;} int A[max];int b[max];int c[max];int d,str[300000];int main () {int N,m,j,i;int k=1,l;while (scanf ("%d%d%d",&l,& N,&M)!=eof) {for (i=0;i<l;i++) scanf ("%d", &a[i]); for (i=0;i<n;i++) scanf ("%d", &b[i]); for (i=0;i<m;i++) scanf ("%d", &c[i]), int. len=0;for (i=0;i<n;i++) {for (j=0;j<m;j++) {Str[len++]=b[i] +C[J];}} Sort (str,str+len,cmp), int ok;printf ("Case%d:\n", k++), int s;scanf ("%d", &s), for (i=0;i<s;i++) {scanf ("%d", &D) ok=0;for (j=0;j<l;j++) {int left = 0,right = Len,mid = 0;int Goal = D-a[j];while (right >= left) {mid = (right + left) >> 1;if (Str[mid] < goal) left = mid + 1;else if (Str[mid] > goal) right = Mid-1;else{ok=1;break;}} if (OK) break;} if (OK) printf ("yes\n"), Else printf ("no\n");}} return 0;}
Hdoj 2141 Can you find it? "Two-point search + violence"