hdu Can you find it
这道题也是道二分的题,主要有几个注意点:
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的更多相关文章
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
- hdu 4329
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟 a. p(r)= R'/i rel(r)=(1||0) R ...
- HDU 2586
http://acm.hdu.edu.cn/showproblem.php?pid=2586 题意:求最近祖先节点的权值和 思路:LCA Tarjan算法 #include <stdio.h&g ...
随机推荐
- 2.7 编程之美--最大公约数的3种解法[efficient method to solve gcd problem]
[本文链接] http://www.cnblogs.com/hellogiser/p/efficient-method-to-solve-gcd-problem.html [题目] 求两个正整数的最大 ...
- iOS tableView 选中某个cell时 标准的处理方法
以前选中cell时,常常判断选中的行数,但是当cell的顺序发生变化时,就要改动处理函数,特别是行数比较多的时候,很麻烦. 之后运用cell的title的内容判断,但是这种判断与现实的内容密切相关,如 ...
- Linux下配置Hadoop 1.2.1
首先要下载hadoop的包,版本选择1.2.1的,下载地址为:http://mirrors.cnnic.cn/apache/hadoop/common/hadoop-1.2.1/ 这里可以下载hado ...
- TokuDB的特点验证
随着数据量越来越大,越来越频繁的遇到需要进行结构拆分的情况,每一次拆分都耗时很久,并且需要多方配合,非常的不想搞这个事情.于是在@zolker的提醒下想到了13年开源tokuDB,来解决我们迫在眉睫的 ...
- 【读书笔记】读《JavaScript模式》 - 对象创建模式
JavaScript是一种简洁明了的语言,其中并没有在其他语言中经常使用的一些特殊语法特征,比如命名空间(namespace).模块(module).包(package).私有属性(private p ...
- Servlet获取参数
package action; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.Servlet ...
- etc目录名字的意思---挖Linux中的古老缩略语
Unix已经有35年历史了.许多人认为它开始于中世纪,这个中世纪是相对于计算机技术的产生和发展来说的.在过去的时间里,Unix和它的子分支Linux收集有许多的历史和一些完全古老的语言.在这篇技巧文章 ...
- jquery easy ui 1.3.4 快速入门(1)
什么是easyui jQuery EasyUI是一组基于jQuery的UI插件集合,而jQuery EasyUI的目标就是帮助web开发者更轻松的打造出功能丰富并且美观的UI界面.开发者不需要编写复杂 ...
- freopen()——重定向标准输入输出流
freopen()——重定向标准输入输出流 头文件:stdio.h 函数原型:FILE * freopen(const char *filename , const char *type , FIL ...
- AppPoolService-IIS应用程序池辅助类(C#控制应用程序池操作)
using System.Collections.Generic; using System.DirectoryServices; using System.Linq; using Microsoft ...