• HDU-2141


    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

    题意:就是给你3组数,然后再给你一组数,判断这组数中的数是否可以由那3组数中各一个的和。

    AC代码为:可用把前两个数组合并然后让X减去第3组数与合并的数组比较每一个看是相等。

    #include<cstdio>
    #include<iostream>
    #include<vector>
    #include<algorithm>
    using namespace std;


    int main()
    {
    int L,N,M,S,num=1;
    while(~scanf("%d%d%d",&L,&N,&M))
    {

    int a,b,c;
    vector<int> v1,v2,v3,temp;

    for(int i=0;i<L;i++)
    {
    scanf("%d",&a);
    v1.push_back(a);
    }

    for(int i=0;i<N;i++)
    {
    scanf("%d",&b);
    v2.push_back(b);
    }

    for(int i=0;i<M;i++)
    {
    scanf("%d",&c);
    v3.push_back(c); 
    }

    for(int i=0;i<L;i++)
    {
    for(int j=0;j<N;j++)
    {
    temp.push_back(v1[i]+v2[j]);
    }
    }
    sort(temp.begin(),temp.end());

    scanf("%d",&S);
    int flag[S],s1=0;
    while(S--)
    {
    int x,sum=0;
    scanf("%d",&x);

    for(int i=0;i<v3.size();i++)
    {
    int xl=x-v3[i];
    vector<int>::iterator it=lower_bound(temp.begin(),temp.end(),xl);
    if(it!=temp.end() && *it==(x-v3[i]))
    {
    sum++;
    }
    }
    if(sum)
    flag[s1++]=1;
    else
    flag[s1++]=0;

    }

    printf("Case %d: ",num++);
    for(int i=0;i<s1;i++)
    {
    if(flag[i])
    {
    printf("YES ");
    }
    else 
    printf("NO ");
    }


    }

    return 0;
    }


  • 相关阅读:
    Fragments (Android官方文档中文版)
    Fragment and activity的生命周期对比和区别
    frida报错frida.InvalidArgumentError: device not found问题解决方案
    XCTF---easyjava的WriteUp
    XCTF---easyjni的WriteUp
    日常破解--从XCTF的app3题目简单了解安卓备份文件以及sqliteCipher加密数据库
    Anroid关于fragment控件设置长按事件无法弹出Popupwindows控件问题解决记录
    DEX文件解析---2、Dex文件checksum(校验和)解析
    日常破解--XCTF easy_apk
    日常破解---XCTF_APP1获取flag记录
  • 原文地址:https://www.cnblogs.com/csushl/p/9386617.html
Copyright © 2020-2023  润新知