Can you find it?

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.

你以为我是因为被$world final$打击到了而在做水题吗?
没错我就是在做水题.........mhy12345课件上的.....
每个询问枚举$A$然后二分$B+C$
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=,M=N*N;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int a[N],b[N],c[N];
int w[M],n;
int Bin(int v){//printf("Bin %d\n",v);
int l=,r=n;
while(l<=r){
int mid=(l+r)>>;//printf("%d %d %d %d %d\n",l,r,mid,w[mid],v);
if(w[mid]==v) return mid;
else if(v<w[mid]) r=mid-;
else l=mid+;
}
return ;
}
int main(){
freopen("in","r",stdin);
int cas=;
while(scanf("%d%d%d",a,b,c)!=EOF){
printf("Case %d:\n",++cas);
for(int i=;i<=(*a);i++) a[i]=read();
for(int i=;i<=(*b);i++) b[i]=read();
for(int i=;i<=(*c);i++) c[i]=read();
n=;
for(int i=;i<=(*b);i++)
for(int j=;j<=(*c);j++) w[++n]=b[i]+c[j];
sort(w+,w++n);
int Q=read();
while(Q--){
int x=read(),flag=;
for(int i=;i<=(*a);i++) if(Bin(x-a[i])) {flag=;break;}
if(flag) puts("YES");
else puts("NO");
}
}
}
 
 
 

HDU 2141 Can you find it? [二分]的更多相关文章

  1. C - 啥~ 渣渣也想找玩数字 HDU - 2141(有序序列枚举 + 二分优化查找)

    题目描述 可爱的演演又来了,这次他想问渣渣一题... 如果给你三个数列 A[],B[],C[],请问对于给定的数字 X,能否从这三个数列中各选一个,使得A[i]+B[j]+C[k]=X? 输入 多组数 ...

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

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

  3. hdu 2141 (二分)

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

  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?(二分查找变例)

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

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

  8. HDU 2141 Can you find it?【二分查找是否存在ai+bj+ck=x】

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

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

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

随机推荐

  1. linux 操作系统/xxx目录下都是什么文件?

    /bin:存放最常用命令: /dev:设备文件: /etc:存放各种配置文件: /home:用户主目录: /lib:系统最基本的动态链接共享库: /mnt:一般是空的,用来临时挂载别的文件系统: /b ...

  2. move_uploaded_file

    move_uploaded_file() 函数将上传的文件移动到新位置. 若成功,则返回 true,否则返回 false. 语法 move_uploaded_file(file,newloc) 参数 ...

  3. ios开发 第三天

    1.复合 对象可以引用其它对象,可以利用其它对象提供的特性. 通过包含作为实例变量的对象指针实现的. 2.OC是单一继承 3.继承-重构 4.类实例化对象时,self指向了对象的首地址. 类对象isa ...

  4. SQL中MAX()

    列column_name中的数据可以是数值.字符串或是日期时间数据类型.

  5. 自学python Day01

    What is Python 1. 面向对象的解释行语言 2. 非常丰富的库 3. 使用制表符作为语句缩进 (white space) 优点: 1. 免费.开源 2. 可扩展性.可嵌入性 3. 非常丰 ...

  6. php等比例压缩图片

    <?php function resizeImage($im,$maxwidth,$maxheight,$name,$filetype) { $pic_width = imagesx($im); ...

  7. python3 第二十一章 - 函数式编程之return函数和闭包

    我们来实现一个可变参数的求和.通常情况下,求和的函数是这样定义的: def calc_sum(*args): ax = 0 for n in args: ax = ax + n return ax 但 ...

  8. git 文件状态与工作区域

    在上一篇简单讲述了文件状态与工作区域,在这里结合相关git命令详细了解文件的状态变更. 目录 1. 介绍 2. 常用命令 3. 实际操作 1. 介绍 git的文件状态是其git核心内容,了解后对后续的 ...

  9. JavaScript小结

    语法小结 /** * Created by M.C on 2017/5/26. */ /*弹框*/ //var message = "Hello world"; //alert(m ...

  10. WebSphere--用户简要表

     Application Server 含有 com.ibm.servlet.personalization.userprofile 软件包中的类,这些类使维护关于 Web 站点访问者的持久信息和利用 ...