Can you find it?
Can you find it? |
| Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others) |
| Total Submission(s): 1140 Accepted Submission(s): 370 |
|
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 |
|
Sample Output
Case 1: |
|
Author
wangye
|
|
Source
HDU 2007-11 Programming Contest
|
|
Recommend
威士忌
|
/*
二分查找嘛
第一遍想的在三个数组整合到一起查找,但是超内存,想了一下,只整合两个数组的话,时间上虽然复杂了,但是内存小了
*/
#include<bits/stdc++.h>
#define MAX 505
using namespace std;
long long a[MAX],b[MAX],c[MAX],d[MAX*MAX];
int BinarySearch(long long num[],long long end,long long n)/*二分查找*/
{
long long l=,r=end,mid;
while(l<=r)
{
mid=(l+r)/;
if(num[mid]==n)
return ;
if(num[mid]>n)
r=mid-;
else if(num[mid]<n)
l=mid+;
}
if(num[l]==n)
return ;
return ;
}
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
long long L,N,M,t,n;
int Case=;
while(scanf("%lld%lld%lld",&L,&N,&M)!=EOF)
{
for(int i=;i<L;i++)
scanf("%lld",&a[i]);
for(int i=;i<N;i++)
scanf("%lld",&b[i]);
for(int i=;i<M;i++)
scanf("%lld",&c[i]);
long long len=;
for(int i=;i<L;i++)
for(int j=;j<N;j++)
d[len++]=a[i]+b[j];
sort(d,d+len);
scanf("%lld",&t);
printf("Case %d:\n",Case++);
while(t--)
{
scanf("%lld",&n);
int f=;
for(int i=;i<M;i++)
{
if(BinarySearch(d,len,n-c[i]))
{
f=;
break;
}
}
if(f)
puts("YES");
else
puts("NO");
}
}
}
随机推荐
- EOutOfResources字符异常
近日,用Delphi编程时,遇到一个莫名其妙的异常:EOutOfResources,这是一个可以重复再现的异常.开始以为是程序中创建的对象太多,导致占用了过多的资源,引起了这个异常.于是在代码中将许多 ...
- Java数据结构和算法总结-数组、二分查找
前言:在平时开发中数组几乎是最基本也是最常用的数据类型,相比链表.二叉树等又简单很多,所以在学习数据和算法时用数组来作为一个起点再合适不过了.本篇博文的所有代码已上传 github ,对应工程的 ar ...
- 学习Matplotlib
介绍 Matplotlib是一个Python 2D绘图库,可以跨平台生成各种硬拷贝格式和交互式环境的出版品质量图.Matplotlib可用于Python脚本,Python和IPythonshell,j ...
- Free Goodies UVA - 12260 贪心
Free Goodies Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu [Submit ...
- vue学习之指令简写以及事件笔记
1.v-bind:××× 可简写为 :××× 2.v-on:××× 可简写为 @××× 例: v-on:click 可简写为 @click (官网文档介绍) 3.vue处理事件 <!-- 阻止单 ...
- __无标题栏的窗口拖动___javafx
遇到困难::添加mouseevent监听,我用的mouse_DragedDetected配合MouseEvent.Pressed,,闪的不行,后来借鉴swing的pressed,move,releas ...
- M-定在下边的区域
1 效果 2 布局 3 样式
- Quartz.NET实现作业调度
一.Quartz.NET介绍 Quartz.NET是一个强大.开源.轻量的作业调度框架,是 OpenSymphony 的 Quartz API 的.NET移植,用C#改写,可用于winform和asp ...
- 在C#中实现串口通信的方法
通常,在C#中实现串口通信,我们有四种方法: 第一:通过MSCOMM控件这是最简单的,最方便的方法.可功能上很难做到控制自如,同时这个控件并不是系统本身所带,所以还得注册,不在本文讨论范围.可以访问h ...
- eNSP关闭保存文件的提示信息
总是提示如下信息: Oct 12 2017 23:49:24-08:00 Huawei DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25.191.3. ...