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");
}
}
}
随机推荐
- 使用node.js检查js语法错误
如果没有一些工具和插件写JavaScript代码遇到语法错误找起来很费时间,请教了同事怎么用node.js检查 用浏览器测试的时候报语法错误. 1.点击红圈中的蓝色按钮,下次刷新是会在抛出异常的时候自 ...
- Python dict operation introduce
字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在花括号({})中 ,格式如下所示: d = ...
- Power Strings poj2406(神代码)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 29402 Accepted: 12296 D ...
- 嵌入式linux开发之工具------tftp
我在嵌入式linux开发中用到tftp的地方主要有2个方面: 1.是在嵌入式目标板启动时,bootloader启动时通过uEnv文件,下载dtb文件和kernel文件: 2.是在嵌入式目标板启动后,通 ...
- 我的第一个python web开发框架(4)——数据库结构设计与创建
小白做好前端html设计后,马上开始进入数据库结构设计步骤. 在开始之前,小白回忆了一下老大在公司里培训时讲过的数据库设计解说: 对于初学者来说,很多拿到原型时不知道怎么设计数据表结构,这是很正常的事 ...
- Asp.net MVC4高级编程学习笔记-视图学习第三课Razor页面布局20171010
Razor页面布局 1) 在布局模板页中使用@RenderBody标记来渲染主要内容.比如很多web页面说头部和尾部相同,中间内容部分使用@RenderBody来显示不同的页面内容. 2) 在布局 ...
- Python实战之Selenium自动化测试web登录(2)
#!/usr/bin/env python3 # -*- coding:utf-8 -*- from selenium import webdriver from selenium.webdriver ...
- wxPython中菜单、按钮学习
---恢复内容开始--- wx.Window 是一个基类,许多构件从它继承.包括 wx.Frame 构件.技术上这意味着,我们可以在所有的 子类中使用 wx.Window 的方法.我们这里介绍它的几种 ...
- 【转】 Python subprocess模块学习总结
从Python 2.4开始,Python引入subprocess模块来管理子进程,以取代一些旧模块的方法:如 os.system.os.spawn*.os.popen*.popen2.*.comman ...
- Weave Scope 容器地图 - 每天5分钟玩转 Docker 容器技术(80)
Weave Scope 的最大特点是会自动生成一张 Docker 容器地图,让我们能够直观地理解.监控和控制容器.千言万语不及一张图,先感受一下. 下面开始实践 Weave Scope. 安装 执行如 ...