Can you find it?

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

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

题意:给出三个数列ABC,从ABC各取一个整数求是否能够等于X,是则输出YES,否NO。

三组500直接查找会超时

可将A+B+C=X转换为A+B=X-C

之后即可将等式两边看做两个整体进行二分查找。

AC代码:

 #include<bits/stdc++.h>
using namespace std; int a[],b[],c[];
int num[]; int bin(int q[],int x,int y){
int left=,right=x,mid;
while(left<=right){
mid=(left+right)/;
if(q[mid]==y)
return ;
if(q[mid]>y)
right=mid-;
else
left=mid+;
}
return ;
} int main(){
int l,n,m,s,ans=;
while(cin>>l>>n>>m){
ans++;
for(int i=;i<l;i++){
cin>>a[i];
}
for(int i=;i<n;i++){
cin>>b[i];
}
for(int i=;i<m;i++){
cin>>c[i];
}
cin>>s;
int x,cnt=; for(int i=;i<l;i++){
for(int j=;j<n;j++){
num[cnt++]=a[i]+b[j];
}
}
sort(num,num+cnt);
printf("Case %d:\n",ans);
while(s--){
cin>>x;
int flag=;
for(int i=;i<m;i++){
int temp=x-c[i];
if(bin(num,cnt-,temp)){
cout<<"YES"<<endl;
flag=;
break;
}
}
if(!flag)
cout<<"NO"<<endl;
}
}
return ;
}

hdu-2141的更多相关文章

  1. hdu 2141 (二分)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 Can you find it? Time Limit: 10000/3000 MS (Java/O ...

  2. hdu 2141 Can you find it?

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2141 Can you find it? Description Give you three sequ ...

  3. hdu 2141 Can you find it?(二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 题目大意:查找是否又满足条件的x值. 这里简单介绍一个小算法,二分查找. /* x^2+6*x- ...

  4. HDU 2141 Can you find it? (二分)

    题目链接: Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/ ...

  5. hdu 2141:Can you find it?(数据结构,二分查找)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

  6. hdu 2141 Can you find it? (二分法)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

  7. Can you find it?(hdu 2141 二分查找)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

  8. hdu 2141 Can you find it?(二分查找变例)

    Problem Description Give you three sequences of numbers A, B, C, then we give you a number X. Now yo ...

  9. HDU 2141 Can you find it? [二分]

    Can you find it? Give you three sequences of numbers A, B, C, then we give you a number X. Now you n ...

  10. Can you find it? HDU - 2141 (二分查找)

    Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate ...

随机推荐

  1. EasyUI基础入门之Droppable(可投掷)

    怎么说呢Droppable这个单词究竟是什么意思,准确来说easyui作者究竟要表达什么意思,还是不大好拿捏的.只是没关系,没有必要纠结与这些细枝末节的东西,依据官网的demo效果,就简单的将之定义为 ...

  2. Allegro PCB中封装焊盘替换操作详解

    Allegro PCB中有些功能在某种情况下使用会产生神奇的效果,但有部分人不会或不熟悉在特定情况下使用某些功能来解决问题.如焊盘替换,有些特殊器件(如下图)封装按照datasheet给出的参考制作, ...

  3. EhCache Monitor的使用

    1.在http://ehcache.org/documentation/monitor.html#Installation_And_Configuration下载ehcache-monitor-kit ...

  4. Flash制作和软件使用

    Flash制作和软件使用 2014-11-09 ——君子善假于物也 引子 虽说FLASH在随着HTML5的发展而受阻,尤其移动终端都不再支持它了,但是在一段时间内还是重要的.近期朋友说要结婚,想弄个电 ...

  5. ECharts整合HT&#160;for&#160;Web的网络拓扑图应用

    ECharts图形组件在1.0公布的时候我就已经有所关注.今天在做项目的时候遇到了图标的需求,在HTfor Web上也有图形组件的功能.可是在尝试了下详细实现后,发现HT for Web的图形组件是以 ...

  6. 谈谈 T 型人才

    谈谈 T 型人才   昨天的图片发模糊了,正好我把这个话题展开聊一聊吧.这个话题是关于复合型人才的,我把它称作 T 型人才. 「全栈」工程师 前一段时间,「全栈」工程师的概念很火,不过大多数时候,「全 ...

  7. 关于arr.map()问题

    最近看map实现原理, Array.prototype._map = function(fn, context) { console.log(fn, context) var temp = []; i ...

  8. SSH实现在WIN7系统下访问虚拟机中的Linux系统

    使用的是centos6.4进行练习的,安装的是vmware8虚拟机.以下是总结的一些步骤: 一.确保vmware使用NAT的连接方式,如做地址.端口映射 首先查看vmware的中网络连接的一些方式:E ...

  9. EasyRTMP实现的一套简单、高效、易用的全平台(Windows/Linux/ARM/Android/iOS)RTMP直播推送库

    本文转自EasyDarwin开源团队成员Kim的博客:http://blog.csdn.net/jinlong0603/article/details/52938980 EasyRTMP介绍 Easy ...

  10. 一款很好的日程安排插件fullcalendar 非常适合OA等系统

    1.插件下载 http://arshaw.com/fullcalendar/download/ 2. <!DOCTYPE html> <meta http-equiv="C ...