Topic Portal
1 /*2 Test Instructions: Give a number, ask if there is AI + bj + ck = = x3 Binary lookup: First calculate sum[l] = A[i] + b[j], for Q, enumerate CK, find if there is a sum + CK = = x4 */5#include <cstdio>6#include <algorithm>7#include <cmath>8 using namespacestd;9 TentypedefLong Longll; One Const intMAXN = 5e2 +Ten; A Const intINF =0x3f3f3f3f; - ll A[MAXN], B[MAXN], C[MAXN]; -ll sum[maxn*MAXN]; the inttot; - - BOOLMy_binary_search (intLintR, ll K) { - while(L <r) { + intMid = (L + r) >>1; - if(Sum[mid] = = k)return true; + Else if(Sum[mid] > k) r =mid; A ElseL = mid +1; at } - return false; - } - - intMainvoid) {//hdoj 2141 Can you find it? - //freopen ("hdoj_2141.in", "R", stdin); in - intL, N, M, s, cas =0; to while(SCANF ("%d%d%d", &l, &n, &m) = =3) { + for(intI=1; i<=l; ++i) scanf ("%i64d", &a[i]); - for(intI=1; i<=n; ++i) scanf ("%i64d", &b[i]); the for(intI=1; i<=m; ++i) scanf ("%i64d", &c[i]); *scanf ("%d", &s); $ Panax Notoginsengprintf ("Case %d:\n", ++CAs); -Sort (A +1, A +1+L); Sort (b +1, B +1+N); Sort (c+1, c+1+m); thetot =0; + for(intI=1; i<=l; ++i) { A for(intj=1; j<=n; ++j) { theSum[++tot] = A[i] +B[j]; + } - } $Sort (sum+1, sum+1+tot); $ -ll mn = a[1] + b[1] + c[1], mx = a[l] + b[n] +C[m]; - while(s--) { thell Q; scanf ("%i64d", &q); - if(Q < MN | | q >mx) {WuyiPuts ("NO");Continue; the } - BOOLFlag =false; Wu for(intI=1; i<=m; ++i) { - intp = Lower_bound (sum+1, sum+1+tot, Q-c[i])-sum; About if(P <1|| P > Tot)Continue; $ if(Sum[p] + c[i] = =q) { -Flag =true; Puts ("YES"); Break; - } - //if (my_binary_search (1, tot, Q-c[i])) { A //flag = true; Puts ("YES"); break; + //} the } - if(!flag) { $Puts ("NO"); the } the } the } the - return 0; in}
Two points find hdoj 2141 Can you find it?