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. Vscode插件--微信小程序格式化以及高亮组件wxml-vscode

    wxml-vscode wxml-vscode 仓库 提问题 安装 通过 F1 或者 CMD + Shift + P 输入 install. 选择: Install Extension. 特性 格式化 ...

  2. Centos7下MySql5.7安装及配置

    安装MySql 软件包: mysql-community-libs-5.7.22-1.el7.x86_64.rpm mysql-community-common-5.7.22-1.el7.x86_64 ...

  3. 利用sysbench进行MySQL OLTP基准测试

      Preface       In order to know clearly about the real performance threshold of database server,we ...

  4. GNU汇编 伪指令

    伪指令 本身并没有所对应的机器码 它只是在编译的时候起作用,或者转换为其他的实际指令来运行 global ascii byte word data equ align @ 下面的例子是在数据段存放数据 ...

  5. 一个优秀的SSH远程终端工具

    SSH远程终端工具是一款在Windows界面下用来访问远端不同系统下的服务器,从而比较好的达到远程控制终端的目的.向我们操控集群的时候,如果每台机器都安装一个显示器和键盘也是一个不小的花费,而远程终端 ...

  6. tp5 使用技巧(持续更新中...)

    tp5 使用技巧(持续更新中...) 1.自动写入时间 create_time和update_time 使用save方法才行,insert方法不生效,不知为何 2.过滤字段 allowfield和st ...

  7. 数据库DDL

    自己对数据库的整理,也是对自己知识的梳理 SQL ( Structure query language ) 结构化查询语言 SQL语言分为4个部分 1.DDL(Data Definition Lang ...

  8. 呕心沥血写的python猜数字

    #猜数字 import random num_rd=random.randint(0,100) count=1 while 1<=count<=10: num_ip=input('请输入0 ...

  9. C# 打开帮助文档,打开电脑中其他应用或者文件

    打开帮助文档 System.Diagnostics.Process.Start(Directory.GetCurrentDirectory() + "\\" + "hel ...

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

    ************************http://git.oschina.net/tuolemi/java这是git的那个网址********************* 函数的重载:在同一 ...