Can you find it?

來源:互聯網
上載者:User

標籤:center   cas   desc   other   can   iss   stl   repr   nts   

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 DescriptionGive 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. 
InputThere 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. 
OutputFor 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 31 2 31 2 31 2 331410
 
Sample Output
Case 1:NOYESNO
 
Authorwangye 
SourceHDU 2007-11 Programming Contest 
Recommend威士忌 
/*二分尋找嘛第一遍想的在三個數組整合到一起尋找,但是超記憶體,想了一下,只整合兩個數組的話,時間上雖然複雜了,但是記憶體小了*/#include<bits/stdc++.h>#define MAX 505using 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:\n",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");        }    }}

 

Can you find it?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.