Can you find it?

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others)
Total Submission(s): 8506    Accepted Submission(s): 2216

Problem Description
Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate if you can find the three numbers Ai, Bj, Ck, which satisfy the formula Ai+Bj+Ck = X.
 
Input
There are many cases. Every data case is described as followed: In the first line there are three integers L, N, M, in the second line there are L integers represent the sequence A, in the third line there are N integers represent the sequences B, in the forth line there are M integers represent the sequence C. In the fifth line there is an integer S represents there are S integers X to be calculated. 1<=L, N, M<=500, 1<=S<=1000. all the integers are 32-integers.
 
Output
For each case, firstly you have to print the case number as the form "Case d:", then for the S queries, you calculate if the formula can be satisfied or not. If satisfied, you print "YES", otherwise print "NO".
 
Sample Input
3 3 3
1 2 3
1 2 3
1 2 3
3
1
4
10
 
Sample Output
Case 1:
NO
YES
NO
 
Author
wangye
 
Source
 
Recommend
威士忌   |   We have carefully selected several similar problems for you:  2289 1597 1551 2298 1016 
 
 //375MS    1228K    1325 B    C++
/* 题意:
给出三行数和Y,问每是否存在行中一个数令
Ai+Bj+Ck==Y
成立 二分法:
笨笨的分析错时间复杂度了
先将两组数据合并,然后排序,然后进行二分
时间复杂度:O(n*n*lgn)... */
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 505
int a[N],b[N],c[N],d[N*N];
int l,n,m;
int cmp(const void*a,const void*b)
{
return *(int*)a-*(int*)b;
}
int main(void)
{
int t,s;
int cas=;
while(scanf("%d%d%d",&l,&n,&m)!=EOF)
{
for(int i=;i<l;i++) scanf("%d",&a[i]);
for(int i=;i<n;i++) scanf("%d",&b[i]);
for(int i=;i<m;i++) scanf("%d",&c[i]);
int cnt=;
for(int i=;i<n;i++)
for(int j=;j<m;j++)
d[cnt++]=b[i]+c[j];
qsort(a,l,sizeof(a[]),cmp);
qsort(d,cnt,sizeof(d[]),cmp);
scanf("%d",&t);
printf("Case %d:\n",cas++);
while(t--){
int flag=;
scanf("%d",&s);
for(int i=;i<l;i++){
int tl=,tr=cnt-;
int tt=s-a[i];
while(tl<tr){
int mid=(tl+tr)/;
if(d[tl]==tt || d[tr]==tt || d[mid]==tt){ //注意此处判断
flag=;break;
}else if(d[mid]<tt)
tl=mid+;
else tr=mid-;
}
if(flag) break;
}
if(flag) puts("YES");
else puts("NO");
}
}
return ;
}

hdu 2141 Can you find it? (二分法)的更多相关文章

  1. hdu 2141 (二分)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 Can you find it? Time Limit: 10000/3000 MS (Java/O ...

  2. hdu 2141 Can you find it?

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2141 Can you find it? Description Give you three sequ ...

  3. hdu 2141 Can you find it?(二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 题目大意:查找是否又满足条件的x值. 这里简单介绍一个小算法,二分查找. /* x^2+6*x- ...

  4. HDU 5269 ZYB loves Xor I (二分法)

    题意: 给出一个序列,对每两个数求异或结果后取最低位的1出来作为一个数,然后求这些数字的和.比如:{a,b,c},结果是lowbit(a^b)+lowbit(a^c)+lowbit(b^a)+lowb ...

  5. HDU 3081 Marriage Match II(二分法+最大流量)

    HDU 3081 Marriage Match II pid=3081" target="_blank" style="">题目链接 题意:n个 ...

  6. HDU 2141 Can you find it? (二分)

    题目链接: Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/ ...

  7. hdu 2141:Can you find it?(数据结构,二分查找)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

  8. Can you find it?(hdu 2141 二分查找)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

  9. 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 ...

随机推荐

  1. 一篇SSM框架整合友好的文章(二)

    上一篇讲述了DAO 层,mybatis实现数据库的连接,DAO层接口设计,以及mybtis和spring的整合.DAO层采用接口设计方式实现,接口和SQL实现的分离,方便维护.DAO层所负责的仅仅是接 ...

  2. 路由传参,path和query的刷新报错js文件丢失

    日常的路由跳转,基本都会用到传参,有两种方式:path + query, name + params 常用的写法: this.$router.push({ path: 'proDetail',quer ...

  3. docker-compose 构建mongodb并导入基础数据示例

    使用docker-compose构建mongodb服务并导入基础数据示例. 1.文件目录结构 ——mongo/ |——docker-compose.yml |——mongo-Dockerfile |— ...

  4. 使用Git将本地项目上传到码云

    01.码云上创建一个项目 testgit (名字随意) 02.进入本地想要上传的目录,然后使用git bash 03.cd到想要上传的目录 04.$ git init 初始化一个git 本地仓库(项目 ...

  5. PHP提取奇数或偶数下标元素

    该功能主要用到 array_filter() 函数,这个函数可以用回调函数过滤数组中的单元.用法: array array_filter ( array $array [, callable $cal ...

  6. QToolBox学习笔记

    抽屉控件效果类似于QQ界面 最外面一层叫工具盒QToolBox QToolBox中装的是QGroupBox,分组的盒子 在分组的盒子QGroupBox中装的是QToolButton.

  7. 笔记-twisted

    笔记-twisted 1.      简介 Twisted is an event-driven networking engine written in Python and licensed un ...

  8. 20145202马超 《Java程序设计》第六周学习总结

    进程:是一个正在执行中的程序,每一个进程都有一个执行程序,该顺序是一个执行路径,或者说是一个控制单元. 线程:就是进程中的一个独立的控制单元,线程在控制着进程的执行. 一个进程至少有一线程. Java ...

  9. P3817 小A的糖果(洛谷月赛)

    P3817 小A的糖果 题目描述 小A有N个糖果盒,第i个盒中有a[i]颗糖果. 小A每次可以从其中一盒糖果中吃掉一颗,他想知道,要让任意两个相邻的盒子中加起来都只有x颗或以下的糖果,至少得吃掉几颗糖 ...

  10. CentOS-6.3-minimal安装gnome桌面环境(转载)

    最近,想学着搞搞linux,从入门安装开始,先装centos6.3-minimal,发现是windowser最不习惯的命令界面,先升级桌面,教程如下. 1.添加一个普通用户,并设置密码useradd  ...