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. 服务器文档下载zip格式 SQL Server SQL分页查询 C#过滤html标签 EF 延时加载与死锁 在JS方法中返回多个值的三种方法(转载) IEnumerable,ICollection,IList接口问题 不吹不擂,你想要的Python面试都在这里了【315+道题】 基于mvc三层架构和ajax技术实现最简单的文件上传 事件管理

    服务器文档下载zip格式   刚好这次项目中遇到了这个东西,就来弄一下,挺简单的,但是前台调用的时候弄错了,浪费了大半天的时间,本人也是菜鸟一枚.开始吧.(MVC的) @using Rattan.Co ...

  2. kubernetes之常见故障排除(一)

    系列目录 由由种种原因,在安装或者使用kubernetes的过程中,可能会遇到各种各样的问题.本篇按照官网的介绍罗列出一些常见的故障,以帮助快速解决一些常见的错误. 安装赛程中出现ebtables o ...

  3. Zabbix 3.0安装

    Server 1. rpm安装zabbix 3.0最新的epel源 rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-re ...

  4. 实现单击列表头对ListView的动态排序

    排序是根据列的类型来的,就ID列来说,int类型的排序结果是3,5,17,而如果你把该列类型改为string,结果就会是17,3,5,如果你定义列的时候不加类型,默认是string,如果是自定义类型, ...

  5. 编译性语言&amp;解释性语言

    计算机是不能理解高级语言.当然也就不能直接执行高级语言了.计算机仅仅能直接理解机器语言,所以不论什么语言,都必须将其翻译成机器语言.不论什么编程语言编写的程序归根究竟都是由底层机器的机器代码(01序列 ...

  6. java中Integer在JDK1.6和JDK1.7中的区别

    运行下面这段代码: System.out.println(Integer.valueOf("127")==Integer.valueOf("127")); Sy ...

  7. 2 Maven使用入门

    一.编写pom.xml文件     Maven项目的核心是pom.xml.POM(Project Object Model,项目对象模型)定义了项目的基本信息,用于描述项目如何构建,声明项目依赖等等. ...

  8. SpringSecurity加密Salt

    Spring Security 加密,默认加salt的输出为:password{salt};然后再对这个加salt后的密码加密存储. 源码如下: protected String mergePassw ...

  9. Android系统shell中的clear命令实现【转】

    本文转载自:http://blog.csdn.net/morixinguan/article/details/73467845 之前一直不太清楚,当我们在shell命令行输入很多命令,会在屏幕上输出一 ...

  10. Redis集群与事务

    redis集群对象JedisCluster不支持事务,但是,集群里面的每个节点支持事务 但是可以用第三方呀 启动下,然后看看事务问题: /usr/local/redis/bin/redis-serve ...