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. wordpress数据库结构及表说明

    数据表结构: wp_commentmeta:存储评论的元数据wp_comments:存储评论wp_links:存储友情链接(Blogroll)wp_options:存储WordPress系统选项和插件 ...

  2. Jmeter之Json Path Extractor 接受上一个请求的响应参数

    最近在使用Jmeter进行接口测试,被一个问题困扰了很久,就是第二个请求如何接收上一个请求响应中的参数,刚开始尝试着用网上普遍说的正则表达式,长了了N多次之,都没有达到我想要的效果,被整的够惨,于是, ...

  3. Jamie and Interesting Graph CodeForces - 916C

    http://codeforces.com/problemset/problem/916/C 好尬的题啊... #include<cstdio> #include<algorithm ...

  4. 记忆化搜索(DFS+DP) URAL 1501 Sense of Beauty

    题目传送门 /* 题意:给了两堆牌,每次从首部取出一张牌,按颜色分配到两个新堆,分配过程两新堆的总数差不大于1 记忆化搜索(DFS+DP):我们思考如果我们将连续的两个操作看成一个集体操作,那么这个操 ...

  5. android动画(3)layout动画,layoutChanged动画及算定义它,ListViewActivity的Layout动画(代码和xm配置两种实现l)

    1.layout切换动画 代码: 本示例是fragment切换.在它的oncreateView中 public class LayoutAnimationFrgmt extends Fragment ...

  6. laravel学习笔记(一)

    laravel 简述 优点:优雅.简洁.工程化(项目架构,协同开发) 版本:2011 June 1.0 ,LTS(long time) ,laravel 5.4 功能:队列.搜索.数据库搜索.定时脚本 ...

  7. java 读取txt,java读取大文件

    java 读取txt,java读取大文件 package com.bbcmart.util; import java.io.File;import java.io.RandomAccessFile;i ...

  8. COGS 495. 窗口

    ★☆   输入文件:window.in   输出文件:window.out   简单对比时间限制:2 s   内存限制:256 MB [问题描述] 给你一个长度为N的数组,一个长为K的滑动的窗体从最左 ...

  9. VBA Promming——入门教程

    VBA Visual Basic for Applications(VBA)是Visual Basic的一种宏语言,是微软开发出来在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言.主要能用来 ...

  10. Linux 常用命令:解压缩

    目录 Linux 常用命令:解压缩 说明 tar 涉及参数说明: 压缩 解压 zip压缩 涉及参数说明: uzip解压 涉及参数说明: gzip 涉及参数说明: 压缩率比较 Linux 常用命令:解压 ...