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. Linux 中将用户添加到指定组的指令

    将一个已有用户 testuser 增加到一个已有用户组 root 中,使此用户组成为该用户的附加用户组,可以使用带 -a 参数的 usermod  指令.-a 代表 append, 也就是将用户添加到 ...

  2. 提高篇(1):RMQ问题与ST表

    RMQ是英文Range Minimum/Maximum Query的缩写,是询问某个区间内的最值,这里讲一种解法:ST算法 ST算法通常用在要多次(10^6级别)询问区间最值的问题中,相比于线段树,它 ...

  3. dubbo 与Spring Cloud 对比

    链接:https://www.zhihu.com/question/45413135/answer/242224410 近期也看到一些分享Spring Cloud的相关实施经验,这对于最近正在整理Sp ...

  4. 【c学习-5】

    int main(){ //二维数组的应用 int i,j; int a[2][3]; for(i=0;i void myFunction(){ int a[3]; int i; int max; f ...

  5. java动态返回一个大对象里多个小对象map返回,el表达式用c:set拼接

    基于堆内存,先把map放到返回值里 Map _map=new HashMap(); modelAndView.addObject("pledgeInsurance",_map);/ ...

  6. ethereum(以太坊)(十二)--应用(一)__集资(构造函数/映射)

    pragma solidity ^0.4.4; contract funder{ //0xca35b7d915458ef540ade6068dfe2f44e8fa733c //0x14723a09ac ...

  7. 【JavaScript高级程序设计】6.1 理解对象

    上一章曾经介绍过,创建自定义对象的最简单方式就是创建一个Object 的实例,然后再为它添加属性和方法,如下所示. var person = new Object(); person.name = & ...

  8. php精华之独孤九剑

    首先分享一个地址 https://segmentfault.com/a/1190000013696265(这个是主要的分享,人家作者写的非常棒

  9. 图解HTTP总结(6)——HTTP首部

    HTTP报文首部 HTTP 协议的请求和响应报文中必定包含 HTTP 首部. 首部内容为客户端和服务器分别处理请求和响应提供所需要的信息. 对于客户端用户来说, 这些信息中的大部分内容都无须亲自查看. ...

  10. POJ 3254 状压DP(基础题)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17749   Accepted: 9342 Desc ...