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. A * B Problem Plus(fft)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1402 hdu_1402:A * B Problem Plus Time Limit: 2000/100 ...

  2. net+Oracle开发过程中遇到的小问题

    最新的项目开始使用Oracle后,5个月之间遇到一些在SqlServer中没有遇到的问题,这里记录并贴上一些常用的解决办法. Oracle相关 一.数据库不同版本还原: 刚开始我们一直使用Oracle ...

  3. 学习Spring必学的Java基础知识(1)----反射

    引述要学习Spring框架的技术内幕,必须事先掌握一些基本的Java知识,正所谓"登高必自卑,涉远必自迩".以下几项Java知识和Spring框架息息相关,不可不学(我将通过一个系 ...

  4. PHP性能分析工具xhprof的安装使用与注意事项

    前言 xhprof由facebook开源出来的一个PHP性能监控工具,占用资源很少,甚至能够在生产环境中进行部署. 它可以结合graphviz使用,能够以图片的形式很直观的展示代码执行耗时. 下面主要 ...

  5. ssh密码

  6. Bootstrap中data-src无法显示图片,但是src可以

    在学习bootstrap时,书中的源码是用的data-src来定义图像位置,但是我在使用的时候无法显示图片:data-src可以在img标签中使用来显示图片吗?我使用src可以,而是用data-src ...

  7. Win7如何解决telnet不是内部或外部命令的方案!听语音

    Telnet用于远程操作互联网中的设备或终端计算机服务器,可以有效的减少现场操作的麻烦.因为设备或终端是遍布整个省或市,有的甚至是国外,如何高效的处理问题是当务之急,除了telnet还可以ssh使用c ...

  8. Python3 的注释

    单行注释 # 这是一个注释 print("Hello, World!") 多行注释 1:3个单引号 ''' 这是多行注释,用三个单引号 这是多行注释,用三个单引号 这是多行注释,用 ...

  9. IT项目角色标准定义

    角色 角色标准定义 项目主管 负责协助项目经理分配资源,确定优先级,协调公司和项目组之间的沟通.保证项目团队一直处于良好的状态中.同时监督项目经理的工作方法,以确保项目以及工件符合公司的发展方向以及用 ...

  10. 【开发技术】Xcode3与xcode4.2模板对比(Xcode4.2开发之一些变化)

    Xcode3中IOS下的Application的模板如下: Navigation_Based Application OpenGL ES Application Tab Bar Application ...