hdu 2141:Can you find it?(数据结构,二分查找)
Can you find it?
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others)
Total Submission(s): 9180 Accepted Submission(s): 2401
1 2 3
1 2 3
1 2 3
3
1
4
10
NO
YES
NO
#include <iostream>
#include <algorithm>
using namespace std;
int qn; //sab数组总数
int sab[];
int binsearch(int q[],int n,int k) //二分查找
{
int left=,right=n,mid;
while(left<=right){
mid = (left+right)/;
if(q[mid]==k)
return mid;
if(q[mid]>k)
right = mid - ;
else
left = mid + ;
}
return ;
}
int main()
{
int l,n,m;
int count = ;
while(cin>>l>>n>>m){
qn = ;
int A[],B[],C[];
for(int i=;i<=l;i++){
cin>>A[i];
}
for(int i=;i<=n;i++){
cin>>B[i];
}
for(int i=;i<=m;i++){
cin>>C[i];
}
for(int i=;i<=l;i++)
for(int j=;j<=n;j++)
sab[qn++] = A[i] + B[j]; //产生sab数列
sort(sab+,sab+qn-); //对sab数列进行排序
int s;
cin>>s;
cout<<"Case "<<count++<<":"<<endl;
while(s--){
int t;
cin>>t;
int i;
for(i=;i<=m;i++){
int tt = t - C[i];
if(binsearch(sab,qn-,tt)){ //查找有没有 x-c
cout<<"YES"<<endl;
break;
}
}
if(i>m)
cout<<"NO"<<endl;
}
}
return ;
}
Freecode : www.cnblogs.com/yym2013
hdu 2141:Can you find it?(数据结构,二分查找)的更多相关文章
- hdu 2141 Can you find it?(二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 题目大意:查找是否又满足条件的x值. 这里简单介绍一个小算法,二分查找. /* x^2+6*x- ...
- hdu 2141 Can you find it?(二分查找变例)
Problem Description Give you three sequences of numbers A, B, C, then we give you a number X. Now yo ...
- HDU 2141 Can you find it?【二分查找是否存在ai+bj+ck=x】
Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate ...
- Go 数据结构--二分查找树
Go 数据结构--二分查找树 今天开始一个Go实现常见数据结构的系列吧.有时间会更新其他数据结构. 一些概念 二叉树:二叉树是每个节点最多有两个子树的树结构. 完全二叉树:若设二叉树的高度为h,除第 ...
- HDU 2141 Can you find it? (二分)
题目链接: Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/ ...
- hdoj 2141 Can you find it?【二分查找+暴力】
Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others ...
- HDU 5878 I Count Two Three (预处理+二分查找)
题意:给出一个整数nnn, 找出一个大于等于nnn的最小整数mmm, 使得mmm可以表示为2a3b5c7d2^a3^b5^c7^d2a3b5c7d. 析:预处理出所有形为2a3 ...
- 题解报告:hdu 2141 Can you find it?(二分)
Problem Description Give you three sequences of numbers A, B, C, then we give you a number X. Now yo ...
- HDU 4941 Magical Forest(map映射+二分查找)杭电多校训练赛第七场1007
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 解题报告:给你一个n*m的矩阵,矩阵的一些方格中有水果,每个水果有一个能量值,现在有三种操作,第 ...
- 数据结构-二分查找(Binary Search)
#include <stdio.h> #include <string.h> #include <stdlib.h> #define LIST_INIT_SIZE ...
随机推荐
- linux cut 命令
cut:以某种方式按照文件的行进行分割 参数列表: -b 按字节选取 忽略多字节字符边界,除非也指定了 -n 标志 -c 按字符选取 -d 自定义分隔符,默认为制表符. -f 与-d一起使用,指定显示 ...
- Echarts实例
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- mysql的grant用法(转)
GRANT USAGE ON *.* TO 'discuz'@'localhost' IDENTIFIED BY PASSWORD '*C242DDD213BE9C6F8DA28D49245BF69F ...
- 摘:C++日期时间与字符串间的转换
VC6中 CString sTime = _T("2007-10-26 13:20:30"); char *charTime = (LPSTR)(LPCTSTR)sTime; CS ...
- Android成长之路-LayoutInflater和inflate的用法
在这里用Tabhost的例子来说明: package cn.csdn.activity; import android.app.TabActivity; import android.os.Bundl ...
- Python图像处理(14):神经网络分类器
快乐虾 http://blog.csdn.net/lights_joy/ 欢迎转载,但请保留作者信息 在opencv中支持神经网络分类器.本文尝试在python中调用它. 和前面的贝叶斯分类器一样.神 ...
- tp请求和响应
一.请求参数 use think\Request; 1.获取方法如下: http://w.tp.com/index/index/index/user/AAA $this->request-> ...
- nodejs 发起http请求
http://nodejs.cn/api/http.html#http_http_request_options_callback http://yijiebuyi.com/blog/8221eb14 ...
- MySQL主从复制状态及数据一致性监测工具
转: https://blog.csdn.net/m0_37814112/article/details/80914713
- Murano环境搭建、使用介绍和思考
murano是OpenStack的Application Catalog服务.推崇AaaS(Anything-as-a-Service)的概念.通过统一的框架和API实现应用程序高速部署和应用程序 ...