Can you find it?

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

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
 
Author
wangye
 
Source
 
Recommend
威士忌   |   We have carefully selected several similar problems for you:  2289 1597 1551 2298 1016 
 
 //375MS    1228K    1325 B    C++
/* 题意:
给出三行数和Y,问每是否存在行中一个数令
Ai+Bj+Ck==Y
成立 二分法:
笨笨的分析错时间复杂度了
先将两组数据合并,然后排序,然后进行二分
时间复杂度:O(n*n*lgn)... */
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 505
int a[N],b[N],c[N],d[N*N];
int l,n,m;
int cmp(const void*a,const void*b)
{
return *(int*)a-*(int*)b;
}
int main(void)
{
int t,s;
int cas=;
while(scanf("%d%d%d",&l,&n,&m)!=EOF)
{
for(int i=;i<l;i++) scanf("%d",&a[i]);
for(int i=;i<n;i++) scanf("%d",&b[i]);
for(int i=;i<m;i++) scanf("%d",&c[i]);
int cnt=;
for(int i=;i<n;i++)
for(int j=;j<m;j++)
d[cnt++]=b[i]+c[j];
qsort(a,l,sizeof(a[]),cmp);
qsort(d,cnt,sizeof(d[]),cmp);
scanf("%d",&t);
printf("Case %d:\n",cas++);
while(t--){
int flag=;
scanf("%d",&s);
for(int i=;i<l;i++){
int tl=,tr=cnt-;
int tt=s-a[i];
while(tl<tr){
int mid=(tl+tr)/;
if(d[tl]==tt || d[tr]==tt || d[mid]==tt){ //注意此处判断
flag=;break;
}else if(d[mid]<tt)
tl=mid+;
else tr=mid-;
}
if(flag) break;
}
if(flag) puts("YES");
else puts("NO");
}
}
return ;
}

hdu 2141 Can you find it? (二分法)的更多相关文章

  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 5269 ZYB loves Xor I (二分法)

    题意: 给出一个序列,对每两个数求异或结果后取最低位的1出来作为一个数,然后求这些数字的和.比如:{a,b,c},结果是lowbit(a^b)+lowbit(a^c)+lowbit(b^a)+lowb ...

  5. HDU 3081 Marriage Match II(二分法+最大流量)

    HDU 3081 Marriage Match II pid=3081" target="_blank" style="">题目链接 题意:n个 ...

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

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

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

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

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

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

  9. 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 ...

随机推荐

  1. 开发必看 | iOS开发常用设计模式!

    ios开发学习中,经常弄不清楚ios的开发模式,今天我们就来进行简单的总结和探讨~(一)代理模式 应用场景:当一个类的某些功能需要由别的类来实现,但是又不确定具体会是哪个类实现.优势:解耦合敏捷原则: ...

  2. 轻量级自动化工具 pssh

    pssh应用场景 pssh是一个用python编写的可以并发在多台服务器上批量执行命令的工具,它支持文件并行复制,远程并行执行命令,其中文件并行复制是pssh的核心功能,也是同类工具中的一个亮点. 要 ...

  3. 在React Native中集成热更新

    最近,在项目DYTT集成了热更新,简单来说,就是不用重新下载安装包即可达到更新应用的目的,也不算教程吧,这里记录一下. 1.热更新方案 目前网上大概有两个比较广泛的方式,分别是 react-nativ ...

  4. JAVAOOP多态

    概念:不同对象对于同一个操作做出的相应不同 实现方法:父类:抽象类 抽象方法 子类:普通类 重写抽象方法 同名 父类:普通类 普通方法 子类:普通类 普通方法 同名 父类:接口 抽象方法 实现类:普通 ...

  5. 在唯一密钥属性“fileExtension”设置为“.”时,无法添加类型为“mimeMap”的重复集合项

    在ASP.NET 网站的配置文件中添加了MIME类型,但是运行网站后在IIS上和页面上提示"在唯一密钥属性“fileExtension”设置为“.woff”时,无法添加类型为“mimeMap ...

  6. 779. K-th Symbol in Grammar

    class Solution { public: int kthGrammar(int N, int K) { return helper(N, K, false); } int helper(int ...

  7. Pandas 文本数据

    Pandas针对字符串配备的一套方法,使其易于对数组的每个元素(字符串)进行操作. 1.通过str访问,且自动排除丢失/ NA值 # 通过str访问,且自动排除丢失/ NA值 s = pd.Serie ...

  8. [Codeforces958A2]Death Stars (medium)(字符串+hash)

    Description 题目链接 Solution 这里用类似hash的方法将判断2个矩阵是否相同的时间降为O(m),总时间复杂度为O(m3) Code #include <cstdio> ...

  9. [BZOJ1045] [HAOI2008] 糖果传递 (中位数)

    Description 题目链接 Solution 这题跟数列的中位数有关, 具体证明见刘汝佳的蓝皮书里 Code #include <cstdio> #include <algor ...

  10. 关于SSM框架项目中jsp页面EL表达式使用的一些疑问(一)

    问题 ssm框架整合中,jsp页面中EL表达式所引用的对象“page”可以在controller中使用mav.addObject(“page”,pag )进行添加,如果省略mav.addObject( ...