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. c语言基础学习02

    =============================================================================涉及到的知识点有:include有两种用法.{ ...

  2. hadoop2.6.0集群搭建

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  3. 修改nopCommerce中的实体

                               对已有实体增加一个属性(对Category增加一个SomeNewProperty)   最近在研究nopcommerce,这里是对官网上文档的学习 ...

  4. WebService短信网关配置

    第一步:WebService框架选择[以CXF为例] 1.下载地址:http://cxf.apache.org/download.html,请事先安装好JDK(本人使用的是apache-cxf-2.7 ...

  5. dedecms 封面模板和列表模板有什么不同

    封面模板,相当于你一个大栏目的封面.举例:你有一个栏目叫做"建站"而下面有很多子栏目,例如代码教程.模板下载.seo经验等,那么封面就相当于这个大栏目的首页,然后您可以在这个页面展 ...

  6. 在MAC电脑上抓取iphone数据包的方法

    一.说明: 1.整个抓包操作的过程中,手机必须一直通过USB链接MAC电脑 2.手机系统要求在IOS5以上,因为使用的RVI技术在IOS5以后的系统中才有 3.抓包过程中,手机可以使用任何网络2G.3 ...

  7. spring问题:java.lang.NoClassDefFoundError: org/aspectj/weaver/tools/PointcutPrimitive

    问题描述: spring的:java.lang.NoClassDefFoundError: org/aspectj/weaver/tools/PointcutPrimitive 解决方案: 缺少jar ...

  8. mybatis_SQL映射(1)

    文章摘录自:http://blog.csdn.net/y172158950/article/details/17258377 1. select的映射 <select id="sele ...

  9. 编程:在屏幕中间分别显示绿色、绿底红色、白底蓝色的字符串 'welcome to masm!'

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  10. 2017-07-04(sudo wc sort)

    sudo 作用 root把本来只能超级用户执行的命令,赋予普通用户执行. 添加 运行visudo命令,在文件底部添加信息即可! sudo -l  查看用户可以运行的命令 use1  ALL=(ALL) ...