Can you find it?

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others)

Total Submission(s): 35782    Accepted Submission(s): 8831

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

思路:

此处可以用暴力求解法以及二分查找法(会节省更多时间)。而二分查找是有对应的STL的。此处是可以用binary_search,是在有序数列中确定给定的元素是否存在。

#include <iostream>
#include <algorithm>
using namespace std;
int a[],b[],c[],sum[],s[];
int main()
{
int l,n,m,i,j,s1,T=;
while(scanf("%d%d%d",&l,&n,&m)!=EOF)
{
T++;
for(i=;i<l;i++)
scanf("%d",&a[i]);
for(i=;i<n;i++)
scanf("%d",&b[i]);
for(i=;i<m;i++)
scanf("%d",&c[i]);
for(i=;i<l;i++)
{
for(j=;j<n;j++)
sum[n*i+j]=a[i]+b[j];
}
sort(sum,sum+l*n);
scanf("%d",&s1);
for(i=;i<s1;i++)
scanf("%d",&s[i]);
printf("Case %d:\n",T);
for(i=;i<s1;i++)
{
for(j=;j<m;)
{
if(binary_search(sum,sum+l*n,s[i]-c[j]))
break;
j++;
}
if(j!=m)
printf("YES\n");
else
printf("NO\n");
}
}
return ;
}

(binary_search) Can you find it hdu2141的更多相关文章

  1. 数据结构和算法:Python实现二分查找(Binary_search)

    在一个列表当中我们可以进行线性查找也可以进行二分查找,即通过不同的方法找到我们想要的数字,线性查找即按照数字从列表里一个一个从左向右查找,找到之后程序停下.而二分查找的效率往往会比线性查找更高. 一. ...

  2. c++ 二分法查找(binary_search)

    #include <iostream> // cout #include <algorithm> // binary_search, sort #include <vec ...

  3. 传智播客C++视频学习笔记(5)

    #include <iostream> using namespace std; void swapInt(int& a, int& b) { int temp = a; ...

  4. python函数(五)

    函数 1.函数基本语法及特性 背景提要 现在老板让你写一个监控程序,监控服务器的系统状况,当cpu\memory\disk等指标的使用量超过阀值时即发邮件报警, 你掏空了所有的知识量,写出了以下代码 ...

  5. c++中级 STL基础学习(二)

    deque 和vector差不多,可以在前端后端插入,一般用deque取代vector,vector只能在后端插入push_back().deque还可以push_front(),但是deque后端插 ...

  6. c++容器使用总结(转载)

    目录 ==================================================== 第一章 容器 第二章 Vector和string 第三章 关联容器 第四章 迭代器 第五 ...

  7. Python数据结构应用4——搜索(search)

    Search是数据结构中最基础的应用之一了,在python中,search有一个非常简单的方法如下: 15 in [3,5,4,1,76] False 不过这只是search的一种形式,下面列出多种形 ...

  8. 05--STL序列容器(List)

    一:List双向链表简介 list是一个双向链表容器,可高效地进行插入删除元素. list不可以随机存取元素,所以不支持at.(pos)函数与[]操作符.It++(ok) it+5(err)list不 ...

  9. 史上最全python面试题详解 (二)(附带详细答案(关注、持续更新))

    23.re的match和search区别? re.match()从开头开始匹配string. re.search()从anywhere 来匹配string. # 多行模式>>> re ...

随机推荐

  1. .apply()用法和call()的区别

    Js apply方法详解我在一开始看到javascript的函数apply和call时,非常的模糊,看也看不懂,最近在网上看到一些文章对apply方法和call的一些示例,总算是看的有点眉目了,在这里 ...

  2. 2-Twenty Fourth Scrum Meeting-20151230

    前言 因为服务器关闭,我们的开发项目也遭遇停滞一个星期.与网站开发负责人员协商之后,29号开放服务器.我们的项目也能够继续下去.比规定的开发时间(截止为2015/12/29)推迟. 事项安排 1.开发 ...

  3. Daily Scrumming* 2015.12.20(Day 12)

    一.团队scrum meeting照片 二.成员工作总结 姓名 任务ID 迁入记录 江昊 任务1090 https://github.com/buaaclubs-team/temp-front/com ...

  4. JAVA程序设计 实验一报告

    北京电子科技学院(BESTI) 实     验    报     告 课程:Java程序设计 班级:1351  姓名:李畅宇  学号:20135129 成绩:             指导教师:娄嘉鹏 ...

  5. Python学习笔记(二)——数据类型

    1.数据类型 Python有五个标准的数据类型: Numbers(数字) String(字符串) List(列表) Tuple(元组) Dictionary(字典) 2.Python数字类型 Pyth ...

  6. 第三个spring冲刺第5、6、7天(三天汇总)

    这三天我们一直在研究选择题的选项插入与切换,现在已经大致完善了,达到了预想的效果,晚点会补上截图.

  7. GCP试用到期再申请

    目标 GCP的免费试用到期了.网传可以续用,看了教程,记录下来. 法一 应该可以直接用一个新gmail账号的.这个方法的难点可能在于注册新账号有门槛.我有一个很久以前注册过的,试着找回了密码,登入GC ...

  8. 学习yii2.0——基础入门

    声明:本文内容来自于yiichina.com的权威指南. 安装 推荐使用composer来安全,可能有点慢(要下载的依赖比较多). composer create-project --prefer-d ...

  9. FreeMarker example all in one

    Pick up from http://demojava.iteye.com/blog/800204

  10. Docker for windows 入门二(Kitematic的使用)

    Kitematic下载地址:https://download.docker.com/kitematic/Kitematic-Windows.zip 下载Kitematic,解压后运行,可以登录连接Do ...