Can you find it?

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
#include <iostream>
#include   <cstring>
#include   <cstdlib>
#include    <cctype>
#include    <cstdio>
#include    <string>
#include <algorithm>
using namespace std;
long long  x,v;
int l,n,m,s;
long long  L[555],N[555],M[555],LN[500*500+500];
bool sreach(long long  k){
    long long  li=1;
    long long  r=v;
    while(li<=r){
        long long  mid=(li+r)/2;
        if(LN[mid]==k)return 1;
        else if(LN[mid]<k)
            li=mid+1;
        else
            r=mid-1;
    }

    return 0;
}
int main()
{
    int t=0;
    while(scanf("%d%d%d",&l,&n,&m)!=EOF){
        for(int i=1;i<=l;i++)
            scanf("%lld",&L[i]);
        for(int i=1;i<=n;i++)
            scanf("%lld",&N[i]);
        for(int i=1;i<=m;i++)
            scanf("%lld",&M[i]);
        v=0;
        for(int i=1;i<=l;i++){
            for(int j=1;j<=n;j++){
               LN[++v]=L[i]+N[j];
               //cout << LN[v] << endl;
            }
        }
        scanf("%d",&s);
        printf("Case %d:\n",++t);

        sort(LN+1,LN+v+1);
        while(s--){
            scanf("%lld",&x);
            int flag=0;
            for(int i=1;i<=m;i++){

                if(sreach(x-M[i])){
                    flag=1;
                    break;
                }

            }
            if(flag)
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    //cout << "Hello world!" << endl;
    return 0;
}

 

全部评论

相关推荐

11-06 10:58
已编辑
门头沟学院 嵌入式工程师
双非25想找富婆不想打工:哦,这该死的伦敦腔,我敢打赌,你简直是个天才,如果我有offer的话,我一定用offer狠狠的打在你的脸上
点赞 评论 收藏
分享
10-30 22:18
已编辑
毛坦厂中学 C++
点赞 评论 收藏
分享
评论
点赞
收藏
分享
正在热议
# 25届秋招总结 #
443000次浏览 4514人参与
# 春招别灰心,我们一人来一句鼓励 #
42077次浏览 535人参与
# 北方华创开奖 #
107462次浏览 600人参与
# 地方国企笔面经互助 #
7969次浏览 18人参与
# 同bg的你秋招战况如何? #
77008次浏览 566人参与
# 实习必须要去大厂吗? #
55793次浏览 961人参与
# 阿里云管培生offer #
120387次浏览 2220人参与
# 虾皮求职进展汇总 #
116056次浏览 886人参与
# 如果你有一天可以担任公司的CEO,你会做哪三件事? #
11650次浏览 289人参与
# 实习,投递多份简历没人回复怎么办 #
2454867次浏览 34858人参与
# 提前批简历挂麻了怎么办 #
149922次浏览 1978人参与
# 在找工作求抱抱 #
906075次浏览 9421人参与
# 如果公司给你放一天假,你会怎么度过? #
4762次浏览 55人参与
# 你投递的公司有几家约面了? #
33209次浏览 188人参与
# 投递实习岗位前的准备 #
1196011次浏览 18550人参与
# 机械人春招想让哪家公司来捞你? #
157641次浏览 2267人参与
# 双非本科求职如何逆袭 #
662333次浏览 7397人参与
# 发工资后,你做的第一件事是什么 #
12793次浏览 62人参与
# 工作中,努力重要还是选择重要? #
35884次浏览 384人参与
# 简历中的项目经历要怎么写? #
86934次浏览 1516人参与
# 参加完秋招的机械人,还参加春招吗? #
20145次浏览 240人参与
# 我的上岸简历长这样 #
452046次浏览 8089人参与
牛客网
牛客企业服务