首页 > 其他 > 详细

HDU 2141 Can you find it?

时间:2019-02-25 23:47:07      阅读:229      评论:0      收藏:0      [点我收藏+]

原题链接:点我转移

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. 

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 3
1 2 3
1 2 3
1 2 3
3
1
4
10

Sample Output

Case 1:
NO
YES
NO
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define PI 3.1415926
using namespace std;
typedef long long ll;
const int maxn=500+7;
const ll mod=1e9+7;
int main()
{
    int a[maxn],b[maxn],c[maxn],sum[maxn*maxn];
    int l,n,m;
    int t=1;
    while(cin>>l>>n>>m)
    {
        for(int i=0; i<l; i++)
            cin>>a[i];
        for(int i=0; i<n; i++)
            cin>>b[i];
        for(int i=0; i<m; i++)
            cin>>c[i];
        for(int i=0; i<l; i++)
            for(int j=0; j<n; j++)
                sum[i*l+j]=a[i]+b[j];
        sort(sum,sum+l*n);
        cout<<"Case "<<t++<<":"<<endl;
        int s;
        cin>>s;
        while(s--)
        {
            int flag=0;
            int r;
            cin>>r;
            for(int i=0; i<m; i++)
                if(binary_search(sum,sum+l*n,r-c[i]))
                {
                    flag=1;
                    break;
                }
            if(flag)
                cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
    }
    return 0;
}

 

HDU 2141 Can you find it?

原文:https://www.cnblogs.com/tp25959/p/10434605.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!