Can you find it?

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others)
Total Submission(s): 37762    Accepted Submission(s): 9221

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
1 2 3
1 2 3
1 2 3
3
1
4
10
 
Sample Output
Case 1:
NO
YES
NO
 
思路:  首先将任意两个数组两两相加,保存到一个数组中,这个数组一定要开大一写,最好是500*500,排序,然后加这个新的数组和第三个数组相加,利用二分的思想进行查找。
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int al[],an[],am[],d[];
int main()
{
int l,n,m,s,flag=,s1;
while(~scanf("%d%d%d",&l,&n,&m))
{
for(int i=;i<=l;i++) scanf("%d",&al[i]);
for(int i=;i<=n;i++) scanf("%d",&an[i]);
for(int i=;i<=m;i++) scanf("%d",&am[i]);
int k=;
for(int i=;i<=l;i++){
for(int j=;j<=n;j++)
d[k++]=al[i]+an[j];
}
sort(d+,d+k);
scanf("%d",&s);
printf("Case %d:\n",flag++);
while(s--)
{
bool sign = false;
scanf("%d",&s1);
for(int i=;i<=m;i++)
{
int left=,right=k;
while(left<=right)
{
int middle = (left+right)/;
if(d[middle]+am[i]==s1) {sign = true; break;}
if(d[middle]+am[i]<s1) left = middle+;
else right= middle -;
}
}
if(sign) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
return ;
}

最新文章

  1. JavaScript - 正则表达之二
  2. Lattice FIFO 使用之FIFO_DC输入输出宽度不同时 的一个注意事项
  3. ArrayList用法
  4. C# 根据身份证号码获取简易信息
  5. UI进阶 科大讯飞(1) 语音听写(语音转换成文字)
  6. php 操作mongodb
  7. NOI2014 随机数生成器
  8. Android SDK无法更新问题解决
  9. selenium高级用法
  10. C风格字符串和C++ string 对象赋值操作的性能比较
  11. 记录各种IE兼容问题,IE6,IE7,IE8,IE9,IE10
  12. C# 图解教程 第一章 C#和.NET框架
  13. python 条件分支与循环
  14. BZOJ4039 : 集会
  15. Classification Truth Table
  16. Caused by: java.sql.BatchUpdateException
  17. mod_fcgid: HTTP request length 136136 (so far) exceeds MaxRequestLen (131072)
  18. HTML初学小技巧
  19. windows vs2017环境下编译webkit 2
  20. EF事务处理封装公用

热门文章

  1. InnoDB Multi-Versioning
  2. https://support.microsoft.com/zh-cn/help/2290714/error-message-when-you-install-office-2010-on-a-windows-7-based-comput
  3. JMETER 使用随机变量
  4. LGBMClassifier参数
  5. 2018710101021-王方-《面向对象(java)程序设计》第十一周学习总结
  6. 201871010128-杨丽霞《面向对象程序设计(java)》第六-七周学习总结
  7. 百度PaddlePaddle:
  8. VIJOS-P1045 Kerry 的电缆网络
  9. luoguP4294 [WC2008]游览计划
  10. [LeetCode] 737. Sentence Similarity II 句子相似度之二