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. 判断标签是否包含class的方法

    if ($(this).find('i').hasClass('l-icon-wuxing')) { //取消收藏 $(this).find('i').removeClass('l-icon-wuxi ...

  2. Lua语言的介绍和编程语言的归类

    Lua 本条目介绍的是一种编程语言.关于关于Lua在维基百科中的使用,请见"维基百科:Lua".关于"Lua"一词的其他意思,请见"卢阿". ...

  3. Caused by: java.sql.SQLException: Couldn't perform the operation getAutoCommit: You can't perform any operations on this connection. It has been automatically closed by Proxool for some reason (see lo

    系统启动,一段时间不操作,然后在来操作时,报错如下: Caused by: java.sql.SQLException: Couldn't perform the operation getAutoC ...

  4. HTML5 Canvas圆盘抽奖应用(适用于Vue项目)

    <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8& ...

  5. dede添加会员功能听语音

    http://jingyan.baidu.com/article/363872ec36d33f6e4ba16fb7.html 其实 dede里面的 会员功能就是圈子模版啦 圈子 安装了 基本上有 1, ...

  6. Effective Java 第三版——26. 不要使用原始类型

    Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将 ...

  7. hive导出查询文件到本地文件的2种办法

    通过HQL语句 可以将hive 中表的数据生成到指定的目录. 有时候 我们可以利用hive来生成统计的中间文件(比源文件小的多的) 方法有如下2种: 1.INSERT OVERWRITE LOCAL ...

  8. Cannot complete the install because one or more required items could not be found

    弄了一天的subclipse也没装上,郁闷~~~~~~~~ 无论采用本地安装还是站点安装都不行,在安装的时候显示错误: Cannot complete the install because one  ...

  9. 红米 Note3 (kenzo)刷入 Lineage OS

    红米 Note3 (kenzo)刷入Lineage OS 的过程 详细的教程请看 Install LineageOS on kenzo 本文做一些额外的补充 0 刷机之的准备工作 如果登陆了 Goog ...

  10. sqlserver存储过程及mybatis调用——待续

    创建带输入参数存储过程 use yanantestgoif exists (select * from sys.objects where name='yanan')drop procedure ya ...