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. Android开发之开机自动启动应用

    package com.raycloud.wolf.autostart; import android.content.BroadcastReceiver; import android.conten ...

  2. HttpServletRequestWrapper模拟实现分布式Session

    HttpSession的内容都放在一个单独的Map中,模拟远程分布式Session. 1.使用HttpServletRequestWrapper创建自定义Request2.使用动态代理包装自定义Req ...

  3. react native与原生的交互

    一.交互依赖的重要组件 react native 中如果想要调用ios  中相关的方法,必须依赖一个重要的组件nativemodules import { NativeModules } from ' ...

  4. fork函数的使用【学习笔记】

    #include "apue.h" ; char buf[] = "a write to stdout\r\n"; int main(void) { int v ...

  5. INFO: Ignoring response <403 https://movie.douban.com/top250>: HTTP status code is not handled or not allowed

    爬取豆瓣电影top250,出现以下报错: 2018-08-11 22:02:16 [scrapy.core.engine] INFO: Spider opened 2018-08-11 22:02:1 ...

  6. LR问题汇总

    关于录制打开IE问题 1.LR11用IE11录制脚本时能打开web页面,但是一直是0事件,也没有脚本代码; 解决方法: LR版本和IE版本兼容性问题,这个问题是我们安装环境时不注意,导致LR无法录制. ...

  7. Web.xml配置----字符过滤器

    添加EncodingFilter类实现Filter接口 import javax.servlet.*;import javax.servlet.http.HttpServletRequest;impo ...

  8. Python中的sort() key含义

    sorted(iterable[, cmp[, key[, reverse]]]) iterable.sort(cmp[, key[, reverse]]) 参数解释: (1)iterable指定要排 ...

  9. AtCoder Beginner Contest 057

    A题 分析:24进制转换 #include<iostream> using namespace std; int main() { int a,b; while(cin>>a& ...

  10. mac下载模块时报错OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/chardet'

    原文地址:https://www.cnblogs.com/liangyan-1989/p/8143129.html 安装完pip后,使用pip install selenium报以下错 OSError ...