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 ...
随机推荐
- ‘close’ was not declared in this scope
‘close’ was not declared in this scope ‘read’ was not declared in this scope ‘sysconf’ was not decla ...
- windows vbs启动多个应用程序并使程序最小化(显示桌面)
windows vbs启动多个应用程序并使程序最小化(显示桌面) CreationTime--2018年7月26日11点18分 Author:Marydon 1.应用场景 每天开机后,都需要打开平 ...
- 关于AWS的备份策略
AWS有一个很强大的功能,就是snapshot,翻译过来就是对EBS进行快照.通俗的说,即是对整个硬盘进行完整的镜像备份.如此一来,在其中一台EC2挂掉的时候,我们迅速的另起一台EC2,并将通过快照恢 ...
- java获取unicode码
public String toUNICODE(String s) { StringBuilder sb=new StringBuilder(); for(in ...
- Android WiFi热点7.1以上版本适配
代码地址如下:http://www.demodashi.com/demo/13907.html 一.准备工作 开发环境: jdk1.8 AS(3.0.1) 运行环境: 华为V10(Android ...
- PHP-密码学算法及其应用-对称密码算法
转自:http://www.smatrix.org/bbs/simple/index.php?t5662.html ////////////////////////////////////////// ...
- 金软PDF转换(x-PDFConper)
一.产品概述 金软PDF转换(x-PDFConper)软件产品是一款能够在手机.平板电脑等移动终端设备上.能够浏览MS Office 的Word.Excel.PowerPoint.PDF 等四种格式文 ...
- WIN10 无法访问2003 server共享
With Windows 10 v1803 or Spring Creators update released I have decided to do a fresh installation o ...
- 【实用代码片段】将json数据绑定到html元素 (转)
jQuery扩展 jQuery.fn.extend({ 'jsonBind':function(json){ var dom=this; dom.find('[json-bind]').each(fu ...
- mybatis中sql语句传入多个参数方法
1 使用map <select id="selectRole" parameterType="map" resultType="RoleMap& ...