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 ...
随机推荐
- eclipse 启动后,啥也不干,就一直在loading descriptor for XXX (XXX为工程名),,其他什么操作都不能操作。 如下图所示,保存文件也无法保存。 这个怎么办?一年好几天,什么都干不了!!!!!
解决办法: 解决办法是 断一下网就好了
- 14.约瑟夫环问题[JosephusProblem]
[题目] n个数字(0,1,…,n-1)形成一个圆圈,从数字0开始,每次从这个圆圈中删除第m个数字(第一个为当前数字本身,第二个为当前数字的下一个数字).当一个数字删除后,从被删除数字的下一个继续删除 ...
- discuz特殊主题插件开发步骤和犯的愚蠢错误
discuz作为国内流行的论坛系统,可谓造福了不少趣味相投的网友们.它让天南地北.国内外有着共同兴趣爱好的人们聚集在一起,分享彼此的喜怒哀乐.心得体会.然而作为discuz的使用者之一,还是个码农,然 ...
- MySQL 全文搜索支持, mysql 5.6.4支持Innodb的全文检索和类memcache的nosql支持
背景:搞个个人博客的全文搜索得用like啥的,现在mysql版本号已经大于5.6.4了也就支持了innodb的全文搜索了,刚查了下目前版本号都到MySQL Community Server 5.6.1 ...
- 【JAVA、C++】LeetCode 016 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...
- codeforces 489B. BerSU Ball 解题报告
题目链接:http://codeforces.com/problemset/problem/489/B 题目意思:给出 n 个 boys 的 skills 和 m 个 girls 的 skills,要 ...
- [Android Pro] 关于Android的HTTP客户端的小秘密
原文:http://android-developers.blogspot.com/2011/09/androids-http-clients.html 译文:http://yunfeng.sinaa ...
- [Android Pro] ant 编译android工程
参考文章: http://blog.csdn.net/xyz_lmn/article/details/7268582?reload http://hubingforever.blog.163.com/ ...
- 记录远程桌面登录者的IP和MAC
WINDOWS 2003 远程桌面不能记录登陆IP真是件头痛的事,本方法可以记录登陆者IP,具体的操作步骤如下: 1.建立一个存放日志的目录,如C盘下建立一个RDP的目录“C:/RDP”. 2.然后在 ...
- Android拼图游戏
效果如下 游戏的设计 首先我们分析下如何设计这款游戏: 1.我们需要一个容器,可以放这些图片的块块,为了方便,我们准备使用RelativeLayout配合addRule实现 2.每个图片的块块,我们准 ...