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

//该题的思想是先合并前两组,然后用题目中的x减去第3组的值
//然后在合并组里面二分查找,看是否能找到一个值与x减去第三组的值相等
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std; const int INF=1e9+7;
const int maxn=510;
typedef long long ll; int l,n,m,S;
int a[maxn],b[maxn],c[maxn],ab[maxn*maxn]; int BinarySearch(int ab[],int h,int t)//二分查找
{
int left=0;
int right=h-1;
int mid=(left+right)/2;
while(left<=right)
{
mid=(left+right)/2;
if(ab[mid]==t)
return 1;
else if(ab[mid]>t)
right=mid-1;
else if(ab[mid]<t)
left=mid+1;
}
return 0;
} int main()
{
int cot=1;
int i,j,k,h,x;
while(scanf("%d %d %d",&l,&n,&m)!=EOF)
{
h=0;
for(i=0; i<l; i++)
scanf("%d",&a[i]);
for(j=0; j<n; j++)
scanf("%d",&b[j]);
for(k=0; k<m; k++)
scanf("%d",&c[k]);
for(i=0; i<l; i++)
for(j=0; j<n; j++)
ab[h++]=a[i]+b[j];
sort(ab,ab+h);
printf("Case %d:\n",cot++);
scanf("%d",&S);
for(int s=0; s<S; s++)
{
scanf("%d",&x);
int flag=0;
for(k=0; k<m; k++)
{
int t=x-c[k];
if(BinarySearch(ab,h,t))
{
printf("YES\n");
flag=1;
break;
}
}
if(!flag) printf("NO\n");
}
}
return 0;
}

Can you find it? HDU - 2141 (二分查找)的更多相关文章

  1. Can you find it?(hdu 2141 二分查找)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

  2. Equations(hdu 1496 二分查找+各种剪枝)

    Equations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  3. Pie(hdu 1969 二分查找)

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  4. hdu 2141 Can you find it?(二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 题目大意:查找是否又满足条件的x值. 这里简单介绍一个小算法,二分查找. /* x^2+6*x- ...

  5. hdu 2141:Can you find it?(数据结构,二分查找)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

  6. hdu 2141 Can you find it?(二分查找变例)

    Problem Description Give you three sequences of numbers A, B, C, then we give you a number X. Now yo ...

  7. HDU 2141 Can you find it?【二分查找是否存在ai+bj+ck=x】

    Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate ...

  8. HDU 2141 Can you find it? (二分)

    题目链接: Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/ ...

  9. 二分查找 HDOJ 2141 Can you find it?

    题目传送门 /* 题意:给出一个数,问是否有ai + bj + ck == x 二分查找:首先计算sum[l] = a[i] + b[j],对于q,枚举ck,查找是否有sum + ck == x */ ...

随机推荐

  1. Codeforces 450B div.2 Jzzhu and Sequences 矩阵快速幂or规律

    Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...

  2. python中拷贝对象的区别

    一.赋值.引用 在python中赋值语句总是建立对象的引用值,而不是复制对象.因此,python变量更像是指针,而不是数据存储区域 这点和大多数语音类似吧,比如C++.Java等 1.先看个例子: v ...

  3. 为什么 .NET 会被叫做 .NET?

    微软开发.NET Framework是在20世纪90年代后期,最初是叫做“下一代Windows服务”(Next Generation Windows Services 简称 NGWS). 那么为什么微 ...

  4. rxjs自定义operator

    rxjs自定义operator

  5. form表单有条件的提交

    form表单提交数据,比如,积分,score,在0--100之间 var score = $('#score').val(); if(score !=''){ if(isNaN(score)){ la ...

  6. 使用inline-block,使前面img,后面空div居中显示在一行后,导致当div中有内容时,div下移问题

    .pro_li img,.pro_sm{display: inline-block; *display:inline;*zoom:1;vertical-align: middle ;} 解决方法:使用 ...

  7. python初步学习-python模块之 os

    os os 模块在运维工作中是很常用的一个模块.通过os模块调用系统命令.os模块可以跨平台使用. 在 import os的时候,建议使用import os而非from os import *.这样可 ...

  8. 使用chardet判断编码方式

    1. chardet是什么 chardet是python中比较常用的一个编码方式检测库,需要注意的是它只检测并返回检测结果,并不负责对原数据做什么处理. 可以使用PIP命令安装: pip instal ...

  9. Linux下文本浏览器lynx

    一般登录到Linux上的时候都是使用Shell登录上去的,但是如果这个时候我们有浏览网页的需求怎么办,比如我刚刚部署上去一个网站,但是我并不知道我有没有部署成功,而且只能在这一台Linux上能够访问到 ...

  10. openjudge-NOI 2.6-2000 最长公共子上升序列

    题目链接:http://noi.openjudge.cn/ch0206/2000/ 题解: 裸题,不解释(题目有毒) #include<cstdio> #include<algori ...