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
解题思路:典型的二分搜索,先将a、b两两求和并排好序,然后二分搜索是否能找到x-c[j]这个值即可。 
AC代码(358ms):
 #include<bits/stdc++.h>
using namespace std;
const int maxn=;
int l,n,m,q,cnt=,x,a[maxn],b,c[maxn];bool flag;
vector<int> vec;
int main(){
while(~scanf("%d%d%d",&l,&n,&m)){
vec.clear();
for(int i=;i<=l;++i)scanf("%d",&a[i]);
for(int i=;i<=n;++i){
scanf("%d",&b);
for(int j=;j<=l;++j)
vec.push_back(a[j]+b);
}
sort(vec.begin(),vec.end());
for(int i=;i<=m;++i)scanf("%d",&c[i]);
scanf("%d",&q);printf("Case %d:\n",cnt++);
while(q--){
scanf("%d",&x);flag=false;
for(int j=;j<=m;++j){
int pos=lower_bound(vec.begin(),vec.end(),x-c[j])-vec.begin();
if(pos!=l*n&&vec[pos]==x-c[j]){flag=true;break;}
}
if(flag)puts("YES");
else puts("NO");
}
}
return ;
}

题解报告:hdu 2141 Can you find it?(二分)的更多相关文章

  1. HDU 2141 Can you find it? [二分]

    Can you find it? Give you three sequences of numbers A, B, C, then we give you a number X. Now you n ...

  2. 题解报告:poj 3061 Subsequence(前缀+二分or尺取法)

    Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...

  3. C - 啥~ 渣渣也想找玩数字 HDU - 2141(有序序列枚举 + 二分优化查找)

    题目描述 可爱的演演又来了,这次他想问渣渣一题... 如果给你三个数列 A[],B[],C[],请问对于给定的数字 X,能否从这三个数列中各选一个,使得A[i]+B[j]+C[k]=X? 输入 多组数 ...

  4. 题解报告:hdu 1398 Square Coins(母函数或dp)

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

  5. 题解报告:hdu 2069 Coin Change(暴力orDP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Problem Description Suppose there are 5 types of ...

  6. 题解报告:hdu 1028 Ignatius and the Princess III(母函数or计数DP)

    Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...

  7. 2015浙江财经大学ACM有奖周赛(一) 题解报告

    2015浙江财经大学ACM有奖周赛(一) 题解报告 命题:丽丽&&黑鸡 这是命题者原话. 题目涉及的知识面比较广泛,有深度优先搜索.广度优先搜索.数学题.几何题.贪心算法.枚举.二进制 ...

  8. cojs 强连通图计数1-2 题解报告

    OwO 题目含义都是一样的,只是数据范围扩大了 对于n<=7的问题,我们直接暴力搜索就可以了 对于n<=1000的问题,我们不难联想到<主旋律>这一道题 没错,只需要把方程改一 ...

  9. cojs 二分图计数问题1-3 题解报告

    OwO 良心的FFT练手题,包含了所有的多项式基本运算呢 其中一部分解法参考了myy的uoj的blog 二分图计数 1: 实际是求所有图的二分图染色方案和 我们不妨枚举这个图中有多少个黑点 在n个点中 ...

  10. CF Educational Round 78 (Div2)题解报告A~E

    CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students​ 依题意模拟即可 #include<bits/stdc++.h> us ...

随机推荐

  1. 修复Xcode升级错误 — PCH File Error

    http://www.rockia.net/2013/03/fix-xcode-update-pch-file-error Error:PCH File Built From A Different ...

  2. 在C/C++中使用VLD检测内存泄漏

    VLD地址:https://kinddragon.github.io/vld/ 若出现内存泄漏,VS输出窗口会有如下提示: 若要确定造成内存泄漏的代码位置,仅需进入工程属性->链接器->调 ...

  3. Android 单击跳转到打电话发短信界面,长按打电话发短信

    <uses-permission android:name="android.permission.CALL_PHONE"/><uses-permission a ...

  4. js数据类型简单介绍

    JS数据类型 ECMAScript中有5种简单的数据类型:Undefined,Null,Boolean,Number,String.还有一种复杂的数据类型--Object(本质上是由一组无序的名值对组 ...

  5. css的书写规范,有哪些注意点

    一.框架为先,细节次之. 先写一些浮动,然后高与宽,然后再是细节方面的书写. 比如写一个浮动容器的样式,我们应该先让这个容器的框架被渲染出来,让大家看到基本的 网站框架.然后再再去渲染容器里面的内容. ...

  6. HDU3746 Cyclic Nacklace —— KMP 最小循环节

    题目链接:https://vjudge.net/problem/HDU-3746 Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others)    M ...

  7. [置顶] SQL Server 2005 双机热备的实现

    [置顶] SQL Server 2005 双机热备的实现 分类: SQLSERVER2011-08-24 21:25 901人阅读 评论(0) 收藏 举报 sql servermicrosoftsql ...

  8. ASP.NET统计图表控件

    近来客户需要将前段时间开发的统计信息用图表展示出来,还要多个图表类型,例如:柱状图.饼图.曲线图.三维图等等.在网上google了一下,发现了三个(也许更多)可以使用的控件.下面我们一起看看这三个控件 ...

  9. UUIDUtils

    package com.cc.hkjc.util; import java.util.UUID; /** * 字符串工具类 *  * @author:匿名 *  */public class UUID ...

  10. LA-3029(扫描线)

    题意: 给定一个n*m的矩阵,一些格子是空地“F”,一些是障碍"R",找出一个全部由F组成的面积最大的子矩阵; 思路: 对每个格子维护up[i][j],le[i][j],ri[i] ...