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. hdu 3367 Pseudoforest 最大生成树★

    #include <cstdio> #include <cstring> #include <vector> #include <algorithm> ...

  2. h5-17-元素拖放

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. 纯js手动分页

    昨天让做个页面,后台提供所有数据,没有做好分页,需要前端js手动分页. 我参考了 http://www.cnblogs.com/jiechn/p/4095029.html 做了些许改动让分页效果更加完 ...

  4. saltstack学习笔记--grains基本操作

    查看当前已经定义的监控项: [root@master ~]# salt "192.168.75.135" grains.items 192.168.75.135:     ---- ...

  5. CF782B The Meeting Place Cannot Be Changed

    题意: The main road in Bytecity is a straight line from south to north. Conveniently, there are coordi ...

  6. checkbox:click事件触发span元素内容改变

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. iOS 随笔 允许所有不安全网络访问项目

    允许任意请求访问app   App Transport Security Settings -> Allow Arbitrary Loads  YES

  8. 一键修改android 字体和图片大小.

    项目中需要动态更改 app的字体和图片, 在查阅中找到的更改主题的解决办法,和单独的修改字体的方法.  这两种方法的确有效果但是实现麻烦,在修改字体的过程中,找到一个额外的方法,  修改字体的实现更改 ...

  9. SQL (一)定义变量以及变量赋值

    1.定义变量:declare @name varchar(20)  用declare定义一个名字为name的字符串类型的变量,变量前面需要加@ 2.为变量赋值:set @name = '%奥迪%' , ...

  10. 洛谷 P2053 [SCOI2007]修车

    题目描述 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的.现在需要安排这M位技术人员所维修的车及顺序,使得顾客平均等待 ...