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. RabbitMQ 使用demo

    1.新建一个控制台应用程序:如图 2.代码如下: using RabbitMQ.Client;using RabbitMQ.Client.Events;using System;using Syste ...

  2. @requestBody注解

  3. 《JavaScript设计模式与开发实践》知识点笔记

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "PingFang SC" } p.p2 { margin: 0.0px ...

  4. 【编程技巧】NSDate,NSDateFormatter,NSTimeInterval

    //获取日期 todaysDate=[NSDate date]; //显示日期和时间 dateFormat = [[NSDateFormatter alloc] init];//NSDate没有自己的 ...

  5. HttpServletRequest cannot be resolved to a type。

    问题描述:HttpServletRequest cannot be resolved to a type.Multiple markers at this line - The import java ...

  6. Java之IO流学习总结【上】

    一.什么是流? 流就是字节序列的抽象概念,能被连续读取数据的数据源和能被连续写入数据的接收端就是流,流机制是Java及C++中的一个重要机制,通过流我们可以自由地控制文件.内存.IO设备等数据的流向. ...

  7. Django实现组合搜索

    一.实现方法 1.纯模板语言实现 2.自定义simpletag实现(本质是简化了纯模板语言的判断) 二.基本原理 原理都是通过django路由系统,匹配url筛选条件,将筛选条件作为数据库查询结果,返 ...

  8. SerialChart串口示波器的成功调试

    2018-01-1601:29:06 深夜更新一波串口示波器! http://t.cn/RQMA3uq 心得体会 总之将数据输出设置为","分割的形式即可 重点注意事项!!!! m ...

  9. css中 padding属性的数值赋予顺序为

    4种可能的情况,举例说明:padding:10px; 四个内边距都是10pxpadding:5px 10px; 上下5px 左右10pxpadding:5px 10px 15px; 上5px 右10p ...

  10. Part 2:模型与后台管理admin站点--Django从入门到精通系列教程

    该系列教程系个人原创,并完整发布在个人官网刘江的博客和教程 所有转载本文者,需在顶部显著位置注明原作者及www.liujiangblog.com官网地址. Python及Django学习QQ群:453 ...