Select a number in each of the three arrays to determine whether the addition can get the target number. At first, I wanted to find impossible~ violent.
Contact two points, after the senior guidance to merge the first two arrays, the first two arrays all possible and save in the new array, and then according to the third array, two points to find a new array to determine whether the number of required
#include"Cstdio"#include"CString"#include"algorithm"#defineMAXN 505using namespacestd;intsum[maxn*MAXN];intTail=0, p=1;BOOLJudgeintBinttarget) { intlow=0, high=tail-1; while(low<=High ) { intMid= (Low+high)/2; if(Sum[mid]+b==target)return true; Else if(Sum[mid]+b<target) low=mid+1; Elsehigh=mid-1; } return false;}intMain () {intLen1,len2,len3; while(SCANF ("%d%d%d", &LEN1,&LEN2,&LEN3)! =EOF) { intNUM1[MAXN],NUM2[MAXN],NUM3[MAXN]; for(intI=0; i<len1;i++) scanf ("%d",&Num1[i]); for(intI=0; i<len2;i++) scanf ("%d",&Num2[i]); for(intI=0; i<len3;i++) scanf ("%d",&Num3[i]); Sort (num3,num3+Len3); Tail=0; memset (SUM,0,sizeof(sum)); for(intI=0; i<len1;i++) for(intj=0; j<len2;j++) Sum[tail++]=num1[i]+Num2[j]; Sort (Sum,sum+tail); intN; scanf ("%d",&N); printf ("Case %d:\n", p++); while(n--) { intTemp,i=0, ok=0; scanf ("%d",&temp); while(!ok&&i<Len3)if(Judge (num3[i++],temp)) ok=1; if(OK) printf ("yes\n"); Elseprintf"no\n"); } } return 0;}View Code
HDU 2141:can you find it? (two points)