• 杭电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 }

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

  • 相关阅读:
    js的event对象 详解
    RestSharp使用详解(1)调用阿里巴巴开放存储服务
    RestSharp使用详解(2)RestSharp的BUG和不足
    WF实例学习笔记:(2)通过Workflow 调用 WCF Data Services 获取数据
    译文:SQL Azure客户端瞬态错误处理最佳实践
    Windbg 基本命令
    RestSharp使用详解(3)OSS文件上传的问题
    Transient Fault Handling and Retry Logic: 瞬间错误处理——重试
    推荐一本免费的Node.js电子书(台湾)
    CSS导航菜单应用滑动门技术的玻璃效果菜单
  • 原文地址:https://www.cnblogs.com/soTired/p/4691178.html
Copyright © 2020-2023  润新知