Two points find hdoj 2141 Can you find it?

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.