Can you find it? Time limit:10000/3000ms (java/other) Memory limit:32768/10000k (Java/other) total submission (s): 274 Accepted SUBM Ission (s): 87Problem descriptiongive 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 Input
3 3 31 2 31 2 31 2 331410
I was wondering what I commented out clearly can reduce the burden of the program run ~ but indeed wrong answer~ commented out on AC ~ ~ ~
Ac-code:
Sample Output
Case 1:noyesno#include <stdio.h> #include <algorithm>using namespace Std;int a[505],b[505],c[505],num[500*500*500+10]; int main () {int l,m,n,i,j,le,k,r,x,s,mid,p=1;while (~scanf ("%d%d%d", &l,&m,&n)) {for (i=0;i<l;i++) scanf ("%d", &a[i]), for (i=0;i<m;i++) scanf ("%d", &b[i]), and for (i=0;i<n;i++) scanf ("%d", &c[i]);p rintf ("Case%d:\n", p++); scanf ("%d", &s); int len=0;for (i=0;i<l;i++) for (j=0;j<m;j++) Num[len++]=a[i]+b[j];sort ( Num,num+len); sort (c,c+n), while (s--) {k=0;scanf ("%d", &x);//if (x<num[0]+c[0]| | X>num[len-1]+c[n-1])//{//printf ("no\n");//continue;//}for (i=0;i<n;i++) {le=0;r=len-1;while (le<=r) {mid= (le+r)/2;if (X-num[mid]==c[i]) {k=1;break;} else if (x-num[mid]<c[i]) r=mid-1;elsele=mid+1;} if (k) break;} if (k) printf ("yes\n"); elseprintf ("no\n");}} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 2141~?? Can you find it? or the dichotomy ~ ~??????