Can you find it?

Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others)
Total Submission(s): 1140 Accepted Submission(s): 370
 
Problem Description
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
 
Author
wangye
 
Source
HDU 2007-11 Programming Contest
 
Recommend
威士忌
 
/*
二分查找嘛
第一遍想的在三个数组整合到一起查找,但是超内存,想了一下,只整合两个数组的话,时间上虽然复杂了,但是内存小了
*/
#include<bits/stdc++.h>
#define MAX 505
using namespace std;
long long a[MAX],b[MAX],c[MAX],d[MAX*MAX];
int BinarySearch(long long num[],long long end,long long n)/*二分查找*/
{
long long l=,r=end,mid;
while(l<=r)
{
mid=(l+r)/;
if(num[mid]==n)
return ;
if(num[mid]>n)
r=mid-;
else if(num[mid]<n)
l=mid+;
}
if(num[l]==n)
return ;
return ;
}
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
long long L,N,M,t,n;
int Case=;
while(scanf("%lld%lld%lld",&L,&N,&M)!=EOF)
{
for(int i=;i<L;i++)
scanf("%lld",&a[i]);
for(int i=;i<N;i++)
scanf("%lld",&b[i]);
for(int i=;i<M;i++)
scanf("%lld",&c[i]);
long long len=;
for(int i=;i<L;i++)
for(int j=;j<N;j++)
d[len++]=a[i]+b[j];
sort(d,d+len);
scanf("%lld",&t);
printf("Case %d:\n",Case++);
while(t--)
{
scanf("%lld",&n);
int f=;
for(int i=;i<M;i++)
{
if(BinarySearch(d,len,n-c[i]))
{
f=;
break;
}
}
if(f)
puts("YES");
else
puts("NO");
}
}
}

随机推荐

  1. 利用Docker快速创建Nginx负载均衡节点

    本文版权归博客园和作者吴双本人共同所有 转载和爬虫请注明原文地址 www.cnblogs.com/tdws 一.Self-Host Kestrel 1. 在vs2017中新建dotnet core2. ...

  2. IOS SDWebImage实现基本原理详解(转载)

    1)当我门需要获取网络图片的时候,我们首先需要的便是URl没有URl什么都没有,获得URL后我们SDWebImage实现的并不是直接去请求网路,而是检查图片缓存中有没有和URl相关的图片,如果有则直接 ...

  3. 在 macOS High Sierra 10.13 搭建 PHP 开发环境

    2017 年 9 月 26 日,苹果公司正式发布了新一代 macOS,版本为 High Sierra (11.13). macOS High Sierra 预装了 Ruby(2.3.3).PHP(7. ...

  4. JAVA 局部变量表

    1. 除了 long,double 占用两个slot 之外,其他类型均占用一个slot. 2.在内容相同的情况下, 实例方法(不加 static) 会比 类方法 (static)对占用一个局部变量位置 ...

  5. 【转】Spark运行过程

    http://www.cnblogs.com/1130136248wlxk/articles/6289717.html

  6. asp.net web api 2.2 基础框架(带例子)

    链接:https://github.com/solenovex/asp.net-web-api-2.2-starter-template 简介 这个是我自己编写的asp.net web api 2.2 ...

  7. 几个 Cookie 操作例子的分析

    MDN 上提供了操作 Cookie 的若干个例子,也有一个简单的 cookie 框架,今天尝试分析一下,最后是 jquery-cookie 插件的分析. document.cookie 的操作例子 例 ...

  8. 【POJ】 1061 青蛙的约会(扩欧)

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 119148   Accepted: 25070 Descript ...

  9. 搭建git远程服务器三步骤

    以前都是使用git,这次由于工作需要,需要自己搭建一个远程git服务器.根据网上的 介绍,捣鼓了一下午,终于把远程git服务器搞定了,这里,做个总结. 搭建git远程服务,首先要安装git和ssh,以 ...

  10. 学习札记 ----wind7下如何安装SqlServer数据库

    1.控制面板 ---找到程序和功能选项 如下图所示: 2.打开程序和功能后进入如下图所示的界面,点击打开或关闭window功能. 3.启动window7自带的IIS功能.如下图所示: 4.如上动作准备 ...