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. PHP计算两个时间差的方法

    <?php //PHP计算两个时间差的方法 $startdate="2010-12-11 11:40:00"; $enddate="2012-12-12 11:45 ...

  2. cocos2dx3.0 对象池

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdzE4NzY3MTA0MTgz/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  3. java基础&amp;&amp;高薪面试

    董鹏老师 ,多年经验总结出 [高薪就业必备]之java基础面试题[更新中]:     第01篇       学习Java基础的目的?       第02天       java语言中有没有gotoke ...

  4. Codeforces Round #267 (Div. 2) B. Fedor and New Game

    After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play ...

  5. dubbo 实战1

    准备:先安装zookeeper,然后进入一下步骤 服务端 1.新建 maven项目 2.pom.xml 内容如下 <?xml version="1.0" encoding=& ...

  6. adb的经常使用命令(android debud bridge)

    android调试桥: adb命令使用须要在系统环境遍历中path中追加adb.exe的完整路径D:\IDE\adt-bundle-windows-x86-20130729\sdk\platform- ...

  7. 使用C#解决部分Win8.1系统窗体每隔几秒失去焦点的问题

    使用了Win8.1 With Update 1后,发现重新启动系统后,当前激活的窗体总是每隔几秒失去焦点.过0.5~1秒焦点回来.导致输入无法正常工作,严重影响使用心情和效率. 在网上找了非常久,也没 ...

  8. [ExtJS5学习笔记]第五节 使用fontawesome给你的extjs5应用添加字体图标

    本文地址:http://blog.csdn.net/sushengmiyan/article/details/38458411本文作者:sushengmiyan-------------------- ...

  9. iOS开发教程:Storyboard全解析-第一部分

    本文转载至http://blog.csdn.net/chang6520/article/details/7945845 感谢原文作者分享     故事版(Storyboard)是一个能够节省你很多设计 ...

  10. 个人开发者帐号--我是如何实现在另一台mac上真机调试的

    本文转载至 : http://blog.csdn.net/chenyong05314/article/details/8689534   注:本人有一台mac电脑,之前申请开发者帐号的时候直接就是在这 ...