这道题也是道二分的题,主要有几个注意点:

1、两个数组的合并的问题,可以将a数组和b数组合并,这样可以降低时间复杂度。

2、二分查找的left和right的变化问题。之前这里一直wa。。。一定要是left=mid+1,right=mid-1;可以测试一下x=3和x=9以及x=10这个特殊的值。

剩下的就是二分查找的问题了。

#include"iostream"
#include"stdio.h"
#include"algorithm"
#include"string.h"
#include"cmath"
#define mx 505
using namespace std;
int l,m,n,s,h;
int a[mx],b[mx],c[mx],ab[mx*mx],x; bool test(int xx)
{
int left=;
int right=h-;
while(left<=right)
{
int mid=(right+left)/;
if(ab[mid]==xx) return true;
else if(ab[mid]>xx) right=mid-;
else left=mid+;
}
return false;
} int main()
{
int i,j,k,p;
int count=;
while(scanf("%d%d%d",&l,&m,&n)==)
{
count++;
for(i=;i<l;i++) cin>>a[i];
for(j=;j<m;j++) cin>>b[j];
for(k=;k<n;k++) cin>>c[k];
h=;
for(i=;i<l;i++)
for(j=;j<m;j++)
{
ab[h++]=a[i]+b[j];//合并a和b
}
sort(c,c+n);sort(ab,ab+h);
cout<<"Case "<<count<<":"<<endl;
cin>>s;
for(p=;p<s;p++){
cin>>x;
int flag=;
for(i=;i<n;i++)
{
int a=x-c[i];
if(test(a)) {flag=;break;}
}
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
return ;
}

hdu Can you find it的更多相关文章

  1. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  3. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  4. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  6. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  7. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

  9. hdu 4329

    problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R ...

  10. HDU 2586

    http://acm.hdu.edu.cn/showproblem.php?pid=2586 题意:求最近祖先节点的权值和 思路:LCA Tarjan算法 #include <stdio.h&g ...

随机推荐

  1. Transfer-Encoding: chunked

    Http1.1中 使用 chunked 编码传送时 没有CONTENT_LENGTH,下载之前无法确定要下载的大小. Wininet中已经内嵌该传输协议,要查看chunked块的大小只能socket底 ...

  2. 1.前端笔记之html

    title: 1.前端笔记之HTML date: 2016-04-04 23:21:52 tags: Python categories: Python --- 作者:刘耀 **出处:http://w ...

  3. 10件在PHP 7中不要做的事情

    刚刚在园子里看到一篇特别好的文章,就拿到我的园子里分享了. 1. 不要使用mysql_函数 这一天终于来了,从此你不仅仅“不应该”使用mysql_函数.PHP 7 已经把它们从核心中全部移除了,也就是 ...

  4. sublime text3083 破解 插件汉化

      sublime text  注册码 1. Sublime Text 2.x 版本 —– BEGIN LICENSE —– Andrew Weber Single User License EA7E ...

  5. win激活查询及修改

    slmgr.vbs -dlv 命令可以查询到Win8.1的激活信息,包括:激活ID.安装ID.激活截止日期!   slmgr.vbs -dli 命令可以查询到操作系统版本.部分产品密钥.许可证状态! ...

  6. 桶排序(bucket sort)

    Bucket Sort is a sorting method that subdivides the given data into various buckets depending on cer ...

  7. iftop

    http://book.51cto.com/art/201409/452431.htm https://wiki.vpsmm.com/iftop/ http://www.cnblogs.com/Alo ...

  8. Oracle 日常应用和操作笔记

    简单整理oracle日常应用笔记. 1.采用excel表格中的数据直接粘贴数据库记录中,默认会在后面加一个空格“”,操作完成后一定要记得对空格匹配然后修改一下. 2.查询数据库里的所有表结构, 采用s ...

  9. 面向服务的体系结构(SOA)——(5)关于MEP(Message Exchange Patterns)

    SOA中的MEP和JavaEE中的JMS类似,当然了就应该是类似的,因为都是关于消息方面的.一个是对系统架构当中消息的解决思路,一个是针对Java平台中的消息的具体解决办法(严格说不是具体的,只是提供 ...

  10. Java Hour 59 JVM Heap

    程序没有方法区释放一段Heap 上的内存,只有JVM 本身可以去回收内存,这个工作单位就是GC. Garbage Collection GC 用来清理对象,同时也用来移动对象减少内存碎片. JVM 指 ...