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

  • 相关阅读:
    ASP 禁止页面被缓存
    关于学习编程的一点想法
    今天下午做的一个关于web前端性能/性能测试的Talk
    错误植入法与老祖宗的智慧
    关闭sitwithwhom.51.net
    让Pywinauto支持中文菜单
    勤学与好问
    LoadRunner 的 web_set_user 函数
    有奖调查——《软件性能测试过程详解与案例剖析》第二版内容调查
    论“响应时间”
  • 原文地址:https://www.cnblogs.com/tp25959/p/10434605.html
Copyright © 2011-2022 走看看