• 杭电2141--Can you find it?


    Can you find it?

    Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others)
    Total Submission(s): 17556    Accepted Submission(s): 4439


    Problem Description
    Give 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.
     

     

    Input
    There are many cases. Every data case is described as followed: In the first line there are three integers L, N, M, in the second line there are L integers represent the sequence A, in the third line there are N integers represent the sequences B, in the forth line there are M integers represent the sequence C. In the fifth line there is an integer S represents there are S integers X to be calculated. 1<=L, N, M<=500, 1<=S<=1000. all the integers are 32-integers.
     

     

    Output
    For each case, firstly you have to print the case number as the form "Case d:", then for the S queries, you calculate if the formula can be satisfied or not. If satisfied, you print "YES", otherwise print "NO".
     

     

    Sample Input
    3 3 3
    1 2 3
    1 2 3
    1 2 3
    3
    1
    4
    10
     

     

    Sample Output
    Case 1: NO YES NO
     

     

    Author
    wangye
     

     

    Source
     

     

    Recommend
    威士忌   |   We have carefully selected several similar problems for you:  2899 2289 1597 1010 2298
    //二分法, 查找的是有序数组的下标,  
     1 #include <iostream>
     2 #include <algorithm>
     3 using namespace std;
     4 int a[550], b[550], c[550]; __int64 d[250050];
     5 int main()
     6 {
     7     int l,m ,n, cas=1;
     8     while(cin >> l >> m >> n)
     9     {
    10         
    11         int i, j, k, t=0;
    12         for(i=0; i<l; i++)
    13             cin >> a[i];
    14         for(i=0; i<m; i++)
    15             cin >> b[i];
    16         for(i=0; i<n; i++)
    17             cin >> c[i];
    18         for(i=0; i<l; i++)
    19             for(j=0 ;j<m; j++)
    20                 d[t++] = a[i] + b[j];         
    21         sort(d, d+t);
    22         printf("Case %d:
    ", cas++);
    23         int g, sum;
    24         scanf("%d", &g);
    25         while(g--)
    26         {
    27             cin >> sum;
    28             int ok = 0;
    29             for(i=0; i<n; i++)
    30             {
    31                 if(d[0] + c[i] <= sum && d[t-1] + c[i] >=sum)   //
    32                 {
    33                     int l=0, r=t-1, mid;
    34                     while(r-l >= 0)
    35                     {
    36                         mid = (l+r)/2;
    37                         if(c[i] + d[mid] > sum) r = mid -1;
    38                         else if(d[mid] + c[i] < sum) l = mid + 1;
    39                         else
    40                         { ok = 1; break;} 
    41                     }
    42                     if(ok) break;
    43                 }
    44             }
    45             if(ok)
    46             printf("YES
    ");
    47             else
    48             printf("NO
    ");
    49         }
    50     }
    51     return 0;
    52 }

    //感觉二分法做的确实有点懵。

  • 相关阅读:
    斐波拉切数列学习笔记
    BPC全面预算管理学习专题(SAP)
    AjaxPro新发现错误处理
    漂亮的页面向导和Tab插件(Jquery)
    从SAP BPC中Entity维设计的理念考虑Web程序中类似文档库之类的设计该考虑的东西
    VBA之Range,cells,offset,end 的区别(转)
    Jquery.Cookie使用方法(转)
    机场市场采购网(www.caigo365.com)亮点介绍电子书(杂志)的应用
    showModalDialog()showModelessDialog()方法使用详解(转)
    微软依赖注入Unity(转)
  • 原文地址:https://www.cnblogs.com/soTired/p/4691178.html
Copyright © 2020-2023  润新知