zoukankan      html  css  js  c++  java
  • HDU 2141 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. 

    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;
    }

    C++ STL Binary search详解:https://www.cnblogs.com/aiguona/p/7281856.html

  • 相关阅读:
    软件工程实验二—结构化分析与设计
    软件工程实验一 软件开发文档与工具的安装与使用
    个人作业三-ATM管理系统
    软件工程个人作业二—举例分析流程图与活动图的区别与联系
    软工个人作业—四则运算
    2020软件工程作业02
    自我介绍
    2019春总结作业
    2019春第四次课程设计实验报告
    2019春第三次课程设计实验报告
  • 原文地址:https://www.cnblogs.com/tp25959/p/10434605.html
Copyright © 2011-2022 走看看