Problem Description
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.
 

Input
There are many cases. Every data case is described as followed: In the first line there are three integers L, N, M, in the second line there are L integers represent the sequence A, in the third line there are N integers represent the sequences B, in the forth
line there are M integers represent the sequence C. In the fifth line there is an integer S represents there are S integers X to be calculated. 1<=L, N, M<=500, 1<=S<=1000. all the integers are 32-integers.
 

Output
For each case, firstly you have to print the case number as the form "Case d:", then for the S queries, you calculate if the formula can be satisfied or not. If satisfied, you print "YES", otherwise print "NO".
 

Sample Input

3 3 3
1 2 3
1 2 3
1 2 3
3
1
4
10
 

Sample Output

Case 1:
NO
YES
NO
题意:给你L个A,N个B,M个C以及S个X,问对于每一个x,能否从A,B,C中各找出一个值,使得A+B+C=X.
思路:这是一道二分题,可以把A+B+C=X看做A+B=X-C,那么我们先把A+B并成一个集合Z,然后枚举X-C的值,二分寻找Z中是否有这个值。本来挺简单的二分,自己做的时候一直考虑二分C数组,时间复杂度怎么算都超了= .= 。
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef long double ldb;
#define inf 99999999
#define pi acos(-1.0)
#define eps 1e-15
#define maxn 506
ll a[maxn],b[maxn],c[maxn],d[2*maxn],e[maxn];
ll bing[maxn*maxn]; int main()
{
int n,m,i,j,cas=0,t,p;
while(scanf("%d%d%d",&n,&m,&t)!=EOF)
{
for(i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
for(i=1;i<=m;i++){
scanf("%lld",&b[i]);
}
int tot=0;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
tot++;
bing[tot]=a[i]+b[j];
}
}
sort(bing+1,bing+1+tot);
for(i=1;i<=t;i++){
scanf("%lld",&c[i]);
}
scanf("%d",&p);
for(i=1;i<=p;i++){
scanf("%lld",&e[i]);
}
cas++;
printf("Case %d:\n",cas);
for(i=1;i<=p;i++){
int flag=0;
for(j=1;j<=t;j++){
int wei=lower_bound(bing+1,bing+1+tot,e[i]-c[j])-bing;
if(bing[wei]==e[i]-c[j]){
flag=1;break;
}
}
if(flag)printf("YES\n");
else printf("NO\n");
}
}
return 0;
}

hdu2141 Can you find it? (二分)的更多相关文章

  1. hdu-2141 Can you find it?---暴力+二分

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2141 题目大意: 给ABC三个数组,给一个X,求是否存在Ai+Bj+Ck = X 思路: 等式转化成 ...

  2. Can you find it?(数组+二分hdu2141)

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

  3. Can you find it? HDU-2141 (二分查找模版题)

    Description Give you three sequences of numbers A, B, C, then we give you a number X. Now you need t ...

  4. HDU2199,HDU2899,HDU1969,HDU2141--(简单二分)

    二分是一种很有效的减少时间开销的策略, 我觉得单列出二分专题有些不太合理, 二分应该作为一中优化方法来考虑 这几道题都是简单的使用了二分方法优化, 二分虽然看似很简单, 但一不注意就会犯错. 在写二分 ...

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

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

  6. BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8748  Solved: 3835[Submi ...

  7. BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]

    2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 3352  Solved: 919[Submit][Stat ...

  8. 整体二分QAQ

    POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...

  9. [bzoj2653][middle] (二分 + 主席树)

    Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b ...

随机推荐

  1. 【Flutter】功能型组件之数据共享

    前言   InheritedWidget提供了一种数据在widget树中从上到下传递.共享的方式,例如在应用的根widget中通过InheritedWidget共享了一个数据,那么便可以在子widge ...

  2. Netty入门一:服务端应用搭建 & 启动过程源码分析

    最近周末也没啥事就学学Netty,同时打算写一些博客记录一下(写的过程理解更加深刻了) 本文主要从三个方法来呈现:Netty核心组件简介.Netty服务端创建.Netty启动过程源码分析 如果你对Ne ...

  3. Linux 文件查看相关的一些命令

    文件压缩解压命令 # 解压 xxx.xz 并删除 xz -d test.tar.xz # 打包成 xxx.tar , 语法: tar -cvf 最后包名.tar ./要打包文件 ./要打包的文件 ta ...

  4. xray—学习笔记

    长亭xray扫描器 简介 xray (https://github.com/chaitin/xray) 是从长亭洞鉴核心引擎中提取出的社区版漏洞扫描神器,支持主动.被动多种扫描方式,自备盲打平台.可以 ...

  5. centos7安装宝塔面板

    在终端下执行如下命令 yum install -y wget && wget -O install.sh http://download.bt.cn/install/install.s ...

  6. 实现所有SAP设备打印机并行打印

    SAP版本:ECC 6.0 701 1.如何实现所有SAP设备打印机并行打印? I.通过事务码:SPAD,进入假脱机管理初始屏幕.点击左上角的菜单中 配置(c)=>输出设备,进入SAP系统 输出 ...

  7. [系列] Go - 基于 GORM 获取当前请求所执行的 SQL 信息

    前言 为了便于精准排查问题,需要将当前的请求信息与当前执行的 SQL 信息设置对应关系记录下来,记录的 SQL 信息包括: 执行 SQL 的当前时间: 执行 SQL 的文件地址和行号: 执行 SQL ...

  8. 二本学生拿到腾讯大厂offer的成长记录

    本人迈莫,是在20年以春招实习生的身份进入鹅厂,经过重重波折,最终成为鹅仔一份子.接下来我会以我亲生经历为例,分享一下普通大学的学生也是可以进去大厂,拭目以待!!! 初入大学 惨遭毒打 时间倒回到17 ...

  9. Py-面向对象,组合,继承

    面向对象 只有特定对象能使用特定的几个方法对象=特征+动作 def dog(name,gender,type): #狗的动作 def jiao(dog): print('一条狗%s,汪汪汪' %dog ...

  10. Bitter.Core系列六:Bitter ORM NETCORE ORM 全网最粗暴简单易用高性能的 NETCore ORM 之 示例 DataTable 模型转换

    当我们查询之前,我们先构造一个查询对象的输出DTO.如下图代码: public class TScoreSearchDto { /// <summary> /// 分数 /// </ ...