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. 浅谈JavaScript的Canvas(绘制图形)

    HTML5中新增加的一个元素canvas,要使用canvas元素,浏览器必须支持html5.通过canvas标签来创建元素,并需要为canvas指定宽度和高度,也就是绘图区域的大小. <canv ...

  2. UsbManager, UsbDevice的简单示例

    activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...

  3. Spring Boot 整合Filter

    两种方法 方法一: 正常创建好Filter类,配置完成 package clc.user.filter; import javax.servlet.Filter; import javax.servl ...

  4. 安装mysql 8.0版本时,使用front连接报1251错误或者navicat 连接报错2059解决方案

    这个错误出现的原因是在mysql8之前的版本中加密规则为mysql_native_password,而在mysql8以后的加密规则为caching_sha2_password. 解决此问题有两种方法, ...

  5. HDU2612 Find a way —— BFS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 Find a way Time Limit: 3000/1000 MS (Java/Others ...

  6. ss连接不上

    突然ss就连接不上了,而vps的ip能ping通,ssh也能登录. 折腾了半天都没解决. 后来解决了,关键点有两个 (1)更改ss的服务端口,原本是9000,随便改为其他的: (2)在switch里设 ...

  7. UIFont 字体样式 [UIFont fontWithName~];

    设置字体样式代码:[UIFont fontWithName:@"Arial-BoldMT" size:15] 下边一一列举: 一:Font Family: American Typ ...

  8. HDU5890:Eighty seven(Bitset优化背包)

    Mr. Fib is a mathematics teacher of a primary school. In the next lesson, he is planning to teach ch ...

  9. 关于base64编码的原理及实现

    我们的图片大部分都是可以转换成base64编码的data:image. 这个在将canvas保存为img的时候尤其有用.虽然除ie外,大部分现代浏览器都已经支持原生的基于base64的encode和d ...

  10. ML一些零散记录

    朴素贝叶斯的假定条件:变量独立同分布 一般情况下,越复杂的系统,过拟合的可能性就越高,一般模型相对简单的话泛化能力会更好一点,增加隐层数可以降低网络误差(也有文献认为不一定能有效降低),提高精度,但也 ...