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. Block Demo

    1.预定义Block typedef  void(^myblock1)(int a,int b); 2.将Block做为类的属性 @property(nonatomic,strong) myblock ...

  2. C语言bitmap的使用技巧

    bitmap是一种以位的状态来表示某种特性的状态的一种操作方式,类似嵌入式中的寄存器操作,在表示某种特性enable/disable的时候很适用且占用的内存空间也很小 比如:做过交换机或者企业网管,路 ...

  3. [err] 1055

    本人mysql安装在ubuntu16.04上,mysql版本是5.7.19:在创建表和插入数据时报了 [Err] 1055 - Expression #1 of ORDER BY clause is ...

  4. WaitAll 和 WhenAll 的使用及区别

    用过.net 异步编程的同学都知道,比以前的多线程编程实现起来真的方便很多,今天把WaitAll和WhenAll这两种编程方式回顾总结一下(当然WaitAny.WhenAny是一样的操作) 1:Wai ...

  5. HDFS概述(2)————Block块大小设置

    以下内容转自:http://blog.csdn.net/samhacker/article/details/23089157?utm_source=tuicool&utm_medium=ref ...

  6. 关于select的一个错误---属性选择器

    错误: jquery 获取下拉框 text='1'的 option 的value 属性值  我写的var t= $("#selectID option[text='1']).val() ; ...

  7. Java并发/多线程系列——初识篇

    回到过去,电脑有一个CPU,一次只能执行一个程序.后来多任务处理意味着计算机可以同时执行多个程序(AKA任务或进程).这不是真的"同时".单个CPU在程序之间共享.操作系统将在运行 ...

  8. hdu2157矩阵快速幂

    How many ways?? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. css 浮动和清除浮动

    在写页面布局的过程中,浮动是大家经常用的属性.在好多的排版布局中都是用的的浮动比如说下面这些地方都是应用到了浮动. 在我学习浮动的时候可是熬坏了脑筋,在这里我分享一下我对浮动这块知识的总结. 一.浮动 ...

  10. 扩展jquery.validate自定义验证,自定义提示,本地化

    <!DOCTYPE html> <html> <head> <meta name="viewport" content="wid ...