题目传送门

 /*
题意:给出一个数,问是否有ai + bj + ck == x
二分查找:首先计算sum[l] = a[i] + b[j],对于q,枚举ck,查找是否有sum + ck == x
*/
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std; typedef long long ll;
const int MAXN = 5e2 + ;
const int INF = 0x3f3f3f3f;
ll a[MAXN], b[MAXN], c[MAXN];
ll sum[MAXN*MAXN];
int tot; bool my_binary_search(int l, int r, ll k) {
while (l < r) {
int mid = (l + r) >> ;
if (sum[mid] == k) return true;
else if (sum[mid] > k) r = mid;
else l = mid + ;
}
return false;
} int main(void) { //HDOJ 2141 Can you find it?
//freopen ("HDOJ_2141.in", "r", stdin); int l, n, m, s, cas = ;
while (scanf ("%d%d%d", &l, &n, &m) == ) {
for (int i=; i<=l; ++i) scanf ("%I64d", &a[i]);
for (int i=; i<=n; ++i) scanf ("%I64d", &b[i]);
for (int i=; i<=m; ++i) scanf ("%I64d", &c[i]);
scanf ("%d", &s); printf ("Case %d:\n", ++cas);
sort (a+, a++l); sort (b+, b++n); sort (c+, c++m);
tot = ;
for (int i=; i<=l; ++i) {
for (int j=; j<=n; ++j) {
sum[++tot] = a[i] + b[j];
}
}
sort (sum+, sum++tot); ll mn = a[] + b[] + c[], mx = a[l] + b[n] + c[m];
while (s--) {
ll q; scanf ("%I64d", &q);
if (q < mn || q > mx) {
puts ("NO"); continue;
}
bool flag = false;
for (int i=; i<=m; ++i) {
int p = lower_bound (sum+, sum++tot, q - c[i]) - sum;
if (p < || p > tot) continue;
if (sum[p] + c[i] == q) {
flag = true; puts ("YES"); break;
}
//if (my_binary_search (1, tot, q - c[i])) {
//flag = true; puts ("YES"); break;
//}
}
if (!flag) {
puts ("NO");
}
}
} return ;
}

二分查找 HDOJ 2141 Can you find it?的更多相关文章

  1. hdoj 2141 Can you find it?【二分查找+暴力】

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

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

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

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

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

  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?【二分查找是否存在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 ...

  7. 二分查找+数学 HDOJ 4342 History repeat itself

    题目传送门 题意:计算从1开始到第n个非完全平方数的开方和 分析:设第n个非完全平方数的值为a,x * x < a < (x+1) * (x+1),而且易得(tmp = sqrt (a) ...

  8. 离散化+线段树/二分查找/尺取法 HDOJ 4325 Flowers

    题目传送门 题意:给出一些花开花落的时间,问某个时间花开的有几朵 分析:这题有好几种做法,正解应该是离散化坐标后用线段树成端更新和单点询问.还有排序后二分查找询问点之前总花开数和总花凋谢数,作差是当前 ...

  9. jvascript 顺序查找和二分查找法

    第一种:顺序查找法 中心思想:和数组中的值逐个比对! /* * 参数说明: * array:传入数组 * findVal:传入需要查找的数 */ function Orderseach(array,f ...

随机推荐

  1. 上传文件表单file,限制上传文件类型的方法--参数accept

    我们使用<input type="file" />来上传文件,但是当你只想要上传某种格式的文件,比如说(jpg)文件时.可以通过accept来限制. <form& ...

  2. codevs 1378 选课

    题目描述 Description 学校实行学分制.每门的必修课都有固定的学分,同时还必须获得相应的选修课程学分.学校开设了N(N<300)门的选修课程,每个学生可选课程的数量M是给定的.学生选修 ...

  3. CentOS虚拟机与本机同步时间

    接着之前的任务,还是为了在VMWare上搭建分布式hadoop集群.搭着搭着注意到虚拟机上的时间和本机是不同步的,而且可以说是乱七八糟,3台虚拟机时间都与本机差了8个小时以上.首先确认不是时区的问题, ...

  4. Codeforces Round #489 (Div. 2) B、C

    B. Nastya Studies Informatics time limit per test 1 second memory limit per test 256 megabytes input ...

  5. <项目><day11>查看用户浏览过的商品

    <项目>查看用户浏览过的商品 1.创建一个entity包储存实体对象 1.1创建一个Product的类存储实体对象 对象具有以下属性,并添加set和get方法,含参和不含参的构造方法,to ...

  6. python加载和使用java的类的方法

    在开发python项目的时候,有时候会用的java的jar包 有这么几个python的三方包可以用: pyjnius:bug list:https://github.com/kivy/pyjnius/ ...

  7. 踩坑录-libreoffice fatal error com.sun.start.ucb.Interactive.AugmentedIOException: a folder could not be created

    错误概要: 1.LibreOffice可以正常使用: 2.启动tomcat报错如下: Fatal error The application cannot be started. ][context= ...

  8. node安装-Win+Linux+Mac osx

    node下载地址,除了Mac osx或Win平台,仅有Linux平台命令安装. Win.Mac 点击即可下载(注:Mac有dmg和pkg安装格式). Linux分为Redhot和Deepin系列,安装 ...

  9. 详细介绍Linux telnet命令的使用

    对Linux系统进行远程登录,Linux telnet命令是必须得掌握的一个知识,虽然telnet并不是唯一的远程登录的方案,但是不可否认它是最常用的,所以很有必要详细了解Linux telnet命令 ...

  10. web 开发之js---js 实现网页中播放wav的一种方法(flash播放器)

    http://blog.csdn.net/whumr1/article/details/6948160