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

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. (转)SQL Server 的事务和锁(一)

    SQL Server 的事务和锁(一)   最近在项目中进行压力测试遇到了数据库的死锁问题,简言之,如下的代码在 SERIALIZABLE 隔离级别造成了死锁: 1 2 3 4 5 6 7 8 9 1 ...

  2. 使用JS构建简单Map(转)

    转载自:http://freejvm.iteye.com/blog/768025 最近使用源生的js处理页面数据,所谓源生的就是指没有经过包装的.最基本的JavaScript代码: 像使用ext,jQ ...

  3. HDU 5510 Bazinga (字符串匹配)

    题目:传送门. 题意:t 组数据,每组 n 个串,对于第 i 个串如果存在 1 到 i-1 中的某个串不是 i 的子串,那么这个第 i 个串符合题意,求 i 的最大值. 题解:KMP,AC自动机也可以 ...

  4. [Android Pro] Android签名与认证详细分析之一(CERT.RSA剖析)

    转载自:http://www.thinksaas.cn/group/topic/335450/ 一.Android签名概述 我们已经知道的是:Android对每一个Apk文件都会进行签名,在Apk文件 ...

  5. Android之Fragment(二)

    本文主要内容 如何管理Fragment回退栈 Fragment如何与Activity交互 Fragment与Activity交互的最佳实践 没有视图的Fragment的用处 使用Fragment创建对 ...

  6. Ubuntu下查看linux版本,内核版本,系统位数,gcc版本

    1. 查看linux版本  sunny@ubuntu:~$cat /etc/issueUbuntu 11.04 \n \l 2. 查看内核版本1) sunny@ubuntu:~$ cat /proc/ ...

  7. SQL 代码创建表格以及CRUD

    create table <表名>( <列名> <数据类型及长度> [not null], <列名> <数据类型及长度>, ... < ...

  8. vsftp 一键安装包

    http://pan.baidu.com/s/1mibAJC8

  9. PHP CI框架学习笔记-分页实现程序

    视图html  <div id="body"> <form action="/index.php/search/index/" method= ...

  10. Android 下载文件 显示进度条

    加入两个权限 一个是联网,另一个是读写SD卡 <uses-permission android:name="android.permission.INTERNET">& ...