• 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): 1140 Accepted Submission(s): 370
     
    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
    HDU 2007-11 Programming Contest
     
    Recommend
    威士忌
     
    /*
    二分查找嘛
    第一遍想的在三个数组整合到一起查找,但是超内存,想了一下,只整合两个数组的话,时间上虽然复杂了,但是内存小了
    */
    #include<bits/stdc++.h>
    #define MAX 505
    using namespace std;
    long long a[MAX],b[MAX],c[MAX],d[MAX*MAX];
    int BinarySearch(long long num[],long long end,long long n)/*二分查找*/
    {
        long long l=0,r=end,mid;
        while(l<=r)
        {
            mid=(l+r)/2;
            if(num[mid]==n)
                return 1;
            if(num[mid]>n)
                r=mid-1;
            else if(num[mid]<n)
                l=mid+1;
        }
        if(num[l]==n)
            return 1;
        return 0;
    }
    int main()
    {
        //freopen("C:\Users\acer\Desktop\in.txt","r",stdin);
        long long L,N,M,t,n;
        int Case=1;
        while(scanf("%lld%lld%lld",&L,&N,&M)!=EOF)
        {
            for(int i=0;i<L;i++)
                scanf("%lld",&a[i]);
            for(int i=0;i<N;i++)
                scanf("%lld",&b[i]);
            for(int i=0;i<M;i++)
                scanf("%lld",&c[i]);
            long long len=0;
            for(int i=0;i<L;i++)
                for(int j=0;j<N;j++)
                        d[len++]=a[i]+b[j];
            sort(d,d+len);
            scanf("%lld",&t);
            printf("Case %d:
    ",Case++);
            while(t--)
            {
                scanf("%lld",&n);
                int f=0;
                for(int i=0;i<M;i++)
                {
                    if(BinarySearch(d,len,n-c[i]))
                    {
                        f=1;
                        break;
                    }    
                }
                if(f)
                    puts("YES");
                else
                    puts("NO");
            }
        }
    }
  • 相关阅读:
    linux 中实现两列数据的互换
    linux中 sort h的作用
    max 内置函数,管理uv 编辑器下面的窗口的显示情况
    时时设定 uv 面板的位置,还有就是 关于属性打开界面的大小
    判断贴图大小很好 同时可以判断文件大小
    两条线中画终点
    锁定控制器,一般在绑定的时候很多用到
    用 脚本编辑器读脚本 也是编辑脚本
    进行随机旋转用于和并东西并
    排列顶点 uv 不过有很大问题
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/5994656.html
Copyright © 2020-2023  润新知