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,c的值,再定义数组d存a和b所有可能的和,用给定的数减去c数组中的数得到k,用二分法在d数组找k值,若能找到输出yes,否则输出no。

 #include<cstdio>
#include<algorithm>
using namespace std;
int a[],b[],c[],d[*];
int main()
{
int j,l,p,m,n,i,k,t,s,num,r,le,mid,key;
num=;
while(scanf("%d %d %d",&l,&m,&n)!=EOF)
{
for(i = ; i < l ; i++)
{
scanf("%d",&a[i]);
}
for(i = ; i < m ; i++)
{
scanf("%d",&b[i]);
}
for(i = ; i < n ; i++)
{
scanf("%d",&c[i]);
}
p=;
for(i = ; i < l ; i++)
{
for(j = ; j < m ; j++)
{
d[p++]=a[i]+b[j];
}
}
sort(c,c+n);
sort(d,d+p);
scanf("%d",&t);
printf("Case %d:\n",++num);
while(t--)
{
scanf("%d",&s);
key=;
for(i = ; i < n ; i++)
{
k=s-c[i];
le=;
r=p-;
while(le <= r)
{
mid=(le+r)/;
if(k == d[mid])
{
key=-;
break;
}
if(k > d[mid])
{
le=mid+;
}
else
{
r=mid-;
}
}
if(key == -) break;
}
if(key == -) printf("YES\n");
else
printf("NO\n");
}
}
}

杭电 2141 Can you find it? (二分法)的更多相关文章

  1. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  2. 杭电ACM题单

    杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最 ...

  3. 杭电oj 4004---The Frog Games java解法

    import java.util.Arrays; import java.util.Scanner; //杭电oj 4004 //解题思路:利用二分法查找,即先选取跳跃距离的区间,从最大到最小, // ...

  4. 杭电acm习题分类

    专注于C语言编程 C Programming Practice Problems (Programming Challenges) 杭电ACM题目分类 基础题:1000.1001.1004.1005. ...

  5. acm入门 杭电1001题 有关溢出的考虑

    最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...

  6. 杭电acm 1002 大数模板(一)

    从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...

  7. 杭电OJ——1198 Farm Irrigation (并查集)

    畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...

  8. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  9. C#利用POST实现杭电oj的AC自动机器人,AC率高达50%~~

    暑假集训虽然很快乐,偶尔也会比较枯燥,,这个时候就需要自娱自乐... 然后看hdu的排行榜发现,除了一些是虚拟测评机的账号以外,有几个都是AC自动机器人 然后发现有一位作者是用网页填表然后按钮模拟,, ...

随机推荐

  1. C#大话设计模式学习总结

    如有雷同,不胜荣欣,如转载,请注明 C#大话设计模式学习总结 一.工厂模式 面向对象的三个特性:封装,继承和多态 1.封装 Class Operate { privatedouble _numberA ...

  2. ssh密钥分发之二:使用sshpass配合ssh-kopy-id编写脚本批量分发密钥:

    使用sshpass配合ssh-kopy-id编写脚本批量分发密钥: 首先sshpass是一个ssh连接时的免交互工具,首先要安装一下: yum install sshpass -y 接下来我们就可以使 ...

  3. 1-3方法的重载(overload)

    之前已经写了一个方法sumInt用来计算两个int类型数字的和,如果要是想计算两个float类型数字的和呢?ok,那就再来写一个sumFloat方法,除此之外,还有long类型,double类型,如果 ...

  4. OC的单例模式

    原文: http://www.galloway.me.uk/tutorials/singleton-classes/ 在iOS开发中,单例是最有用的设计模式之一.它是在代码间共享数据而不需要手动传递参 ...

  5. 134 Gas Station 加油站

    在一条环路上有 N 个加油站,其中第 i 个加油站有汽油gas[i].你有一辆油箱容量无限的的汽车,从第 i 个加油站前往第 i+1 个加油站需要消耗汽油 cost[i].你从其中一个加油站出发,开始 ...

  6. Ansj分词的使用

    jar包下载地址:http://download.csdn.net/download/jj12345jj198999/6020541 博客地址:http://blog.csdn.net/a822631 ...

  7. RedHat7.2安装matplotlib——之Python.h:没有那个文件或目录

    按理说运行下面一句就可以安装了 pip install matplotlib 但是对于我的redhat7.2+python2.7.5,报了下面的错误 _posixsubprocess.c:3:20: ...

  8. webpack采坑十连跳

    4.css.js一同打包进html ---------------- https://www.cnblogs.com/amiezhang/p/9723565.html 依赖内联插件  HtmlWebp ...

  9. shutil模块详解2

    1.shutil.make_archive() 实际上是调用了两个模块来实现压缩打包的功能. zipfile和tarfile两个模块,shutil的两个封装的模块. zip是压缩文件,文件内存会变小, ...

  10. Hibernate中的inverse和cascade属性

    Hibernate中的inverse和cascade属性 inverse的值有两种,"true"和"false".inverse="false&quo ...