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");
}
}
}
随机推荐
- 用sqlserver的自定义函数直接获取多级部门全名
好久没写存储过程了,今日正好同事的开发需要,实现显示多级部门的部门全名称. 如 财务部/会计部/会计一部 部门表 人员表 函数 getOrgAllName --OrgID 72 当前的部门ID A ...
- TEXT宏
TEXT宏是windows程序设计中经常遇到的宏,定义在 <winnt.h>中 TCHAR *P = TEXT("this is a const string"); 如 ...
- pygame_第一个窗口程序
####可以使用python自带的IDLE交互式开发,也可以借助其他的编辑器,我这里采用的pycharm编辑器 1.导入我们所需要的模块 import pygame,sys --导入我们需要的模块 ...
- Huge Mission
Huge Mission Problem Description Oaiei is busy working with his graduation design recently. If he ca ...
- javascript中的DOM介绍(一)
一.基础知识点 1.DOM是文档对象模型,是针对HTML和XML文档的一个API(应用程序接口) 2.DOM描绘了一个层次化的节点数,允许开发人员进行添加,移除个修改等操作 3.IE浏览器中所有的DO ...
- 从头编写 asp.net core 2.0 web api 基础框架 (1)
工具: 1.Visual Studio 2017 V15.3.5+ 2.Postman (Chrome的App) 3.Chrome (最好是) 关于.net core或者.net core 2.0的相 ...
- php使用curl下载指定大小的文件
php中使用基于libcurl的curl函数,可以对目标url发起http请求并获取返回的响应内容.通常的请求方式类似如下的代码: public function callFunction($url, ...
- ListBox数据绑定无效
public class DataList { public List<string> listSource; private DataTable table; public DataLi ...
- django celery的分布式异步之路(二) 高并发
当你跑通了前面一个demo,博客地址:http://www.cnblogs.com/kangoroo/p/7299920.html,那么你的分布式异步之旅已经起步了. 性能和稳定性是web服务的核心评 ...
- Java集合源码分析(一)ArrayList
前言 在前面的学习集合中只是介绍了集合的相关用法,我们想要更深入的去了解集合那就要通过我们去分析它的源码来了解它.希望对集合有一个更进一步的理解! 既然是看源码那我们要怎么看一个类的源码呢?这里我推荐 ...