题目传送门

 /*
题意:给出一个数,问是否有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. 【NOIP2017练习】鏖战字符串(斜率优化DP)

    题意: 在决胜局中,Abwad决定和nbc鏖战字符串,比的是谁能更快地将一个“量子态的字符串”删除.“量子态的字符串”的每个字符都有一个删除难度dif[i].“量子态的字符串”非常顽固,只能先分割成若 ...

  2. Test for Job 图上的动态规划(DAG)

    Test for Job Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 11399   Accepted: 2697 Des ...

  3. poj——1470 Closest Common Ancestors

    Closest Common Ancestors Time Limit: 2000MS   Memory Limit: 10000K Total Submissions: 20804   Accept ...

  4. 使用spark 计算netflow数据初探

    spark是一个高性能的并发的计算平台,而netflow是一种一般来说数量级很大的数据.本文记录初步使用spark 计算netflow数据的大致过程. 本文包括以下过程: 1. spark环境的搭建 ...

  5. ubuntu上跑python连接pg,报错 ImportError: No module named psycopg2

    ubuntu上跑python连接pg,报错  ImportError: No module named psycopg2 root@pgproxy1:~# python /home/zxw/PGWri ...

  6. 第1章 SQL核心

    第1章 SQL核心正在更新内容,请稍后

  7. USRP内部的寄存器

    usrp_regs.hpp #ifndef INCLUDED_USRP2_REGS_HPP #define INCLUDED_USRP2_REGS_HPP ////////////////////// ...

  8. 基于AR谱特征的声目标识别

    本文第一部分先解释AR谱,但并不会给出太多的细节,第二部分介绍几种常见的语音中的特征.有些在之前的博文中已经用过.诸如过零率. 第三部分给出实际操作的过程及识别的效果.本文的目标是通过对DSP採集的声 ...

  9. MySQL通过函数获取字符串汉字拼音首字母大写字符串

    DELIMITER $$ DROP FUNCTION IF EXISTS `Fun_GetPY`$$ CREATE FUNCTION `HIS`.`Fun_GetPY` (in_string VARC ...

  10. 用jquery给元素动态绑定事件及样式

    网页输出的时候,可以用jquery给各种元素绑定事件,或设置样式. 之所以这样做,好处是节省代码,尤其适合元素很多,并且元素的事件对应的函数雷同的情况. 看看以下代码: <div id=&quo ...