hdu 2143 数组合并 二分
Can you find it?
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others)
Total Submission(s): 22312 Accepted Submission(s): 5627
1 2 3
1 2 3
1 2 3
3
1
4
10
NO
YES
NO
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
const int inf=0xffffff;
const int maxn=500+50;
__int64 a[maxn],b[maxn],c[maxn];
__int64 f[maxn*maxn];
int kase=0;
int main()
{
int L,N,M;
__int64 s,sum;
while(scanf("%d%d%d",&L,&N,&M)!=EOF)
{
int num=0;
for(int i=0;i<L;i++)
scanf("%I64d",&a[i]);
for(int i=0;i<N;i++)
scanf("%I64d",&b[i]);
for(int i=0;i<M;i++)
scanf("%I64d",&c[i]);
for(int i=0;i<L;i++)
{
for(int j=0;j<N;j++)
{
f[num++]=a[i]+b[j];
}
}
sort(f,f+num);
printf("Case %d:\n",++kase);
scanf("%I64d",&s);
while(s--)
{
scanf("%I64d",&sum);
int flag=0;
for(int i=0;i<M;i++)
{
int low=0,high=L*N-1;
if(flag) break;
while(low<=high)
{
int mid=(high+low)/2;
if(f[mid]==sum-c[i])
{
flag=1;
break;
}
else if(f[mid]<sum-c[i]) low=mid+1;
else high=mid-1;
}
}
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
return 0;
}
hdu 2143 数组合并 二分的更多相关文章
- 关于table动态添加数据 单元格合并 数组合并
var newArr = [ {"BranchID":1,"BranchName":"城二","BranchFullName&qu ...
- go语言:多个[]byte数组合并成一个[]byte
场景:在开发中,要将多个[]byte数组合并成一个[]byte,初步实现思路如下: 1.获取多个[]byte长度 2.构造一个二维码数组 3.循环将[]byte拷贝到二维数组中 package gst ...
- 论php数组合并
注:尽量不要在循环中操作数据库. 1.两个一维数组合并成一个一维数组 $a = array('morning','afternoon','night'); $b = array('breakfast' ...
- PHP数组合并+与array_merge的区别分析 & 对多个数组合并去重技巧
PHP中两个数组合并可以使用+或者array_merge,但之间还是有区别的,而且这些区别如果了解不清楚项目中会要命的! 主要区别是两个或者多个数组中如果出现相同键名,键名分为字符串或者数字,需要注意 ...
- JS数组键值,数组合并,
eg: var arr = [] arr.test = '测试'; arr.push(1); arr.push(2); arr.obj = '对象'; console.log(arr);// [ 1, ...
- PHP数组合并 array_merge 与 + 的差异
在PHP数组合并出过几次问题都没记住,写下来加强一点记忆 PHP数组在合并时,使用 array_merge 与 + 的差异: 1.array_merge(array $array1 [, array ...
- Python数组合并
Python数组合并 a = [1, 2] b = [3, 4] c = a + b print(c) # [1, 2, 3, 4]
- PHP数组合并的常见问题
一维数组的合并 <?php $arr1=array("a","b","c"); $arr2=array("c",& ...
- php二位数组合并
转自:http://www.cnblogs.com/losesea/archive/2013/06/14/3134900.html 题目:有以下2个二维数组 1$a=Array(0 => Arr ...
随机推荐
- Tarjan求极大强连通分量模板
#include<iostream> #include<cstring> #include<cstdio> #include<stack> #inclu ...
- [Leetcode][016] 3Sum Closest (Java)
题目: https://leetcode.com/problems/3sum-closest/ [标签]Array; Two Pointers [个人分析] 这道题和它的姊妹题 3Sum 非常类似, ...
- PHP扩展开发(2) - VS2013环境搭建
1. 安装VS2013 2. Cygwin安装 3. 下载Windows的PHP源码 4. 修改~/ext/ext_skel_win32.php 加上 $cygwin_path = 'c:\c ...
- text-align:justify小例子
一个使用 text-align: justify; 使元素均匀分布的小例子: <!DOCTYPE html> <html lang="en"> <he ...
- tomcat 显示目录文件列表
conf/web.xml中,listings改为true,重启 http://liusu.iteye.com/blog/794613 <servlet> <servlet-name& ...
- python编程中在ubuntu中安装虚拟环境及环境配置
1.升级python包管理工具pip pip install --upgrade pip 备注:当你想升级一个包的时候 `pip install --upgrade 包名` 2.python虚拟环境安 ...
- 所谓has a 和 is a
在 C# 中 很好理解: { is a: 继承关系. has a: 成员关系,其他类是本类的成员.} 在C++ 中稍微复杂一点: { 由于有多重继承, 继承也可能是has a,类似C# ...
- 自制单片机之七……RS232串口
在我的板子上其它的部分都已完成了,现在就剩下RS232串口了.串口对于单片机很重要,有了它就可以和PC通信了,可以用PC来控制你的单片机,也可以将你单片机上采集的数据传到PC上. 留的位置好像有点挤. ...
- VC 隐藏托盘图标
苦苦寻找的隐藏托盘图标的方法,今天终于搞定,献给大家! #include <atlbase.h> #include <atlconv.h> #include <CommC ...
- spring framework 4 源码阅读(2)---从ClassPathXmlApplicationContext开始
Application初始化日志 15:23:12.790 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemProperti ...