Can you find it?

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

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
 
lower_bound提交就会出错,binary_search()也可以过
 #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
int a[],b[],c[],x;
__int64 su[*];
int l,n,m,s,u;
int d=,sum;
bool solve(int x)
{
int i,k;
int ans;
for(i=;i<m;i++)
{
ans=x-c[i];
int l=,r=u-,mid,e;
while(l<=r)
{
mid=(l+r)/;
if(su[mid]==ans) return ;
else if(su[mid]>ans) r=mid-;
else l=mid+;
}
}
return ;
}
int main()
{
int i,j;
freopen("in.txt","r",stdin);
while(scanf("%d%d%d",&l,&n,&m)!=EOF)
{
for(i=;i<l;i++) scanf("%d",&a[i]);
for(i=;i<n;i++) scanf("%d",&b[i]);
for(i=;i<m;i++) scanf("%d",&c[i]);
scanf("%d",&s);
u=;
for(i=;i<l;i++)
for(j=;j<n;j++)
su[u++]=a[i]+b[j];
sort(su,su+u);
printf("Case %d:\n",d++);
for(i=;i<s;i++)
{
scanf("%d",&x);
if(solve(x)) printf("YES\n");
else printf("NO\n");
}
}
}

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

  1. Equations(hdu 1496 二分查找+各种剪枝)

    Equations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. Pie(hdu 1969 二分查找)

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

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

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

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

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

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

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

    Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate ...

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

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

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

  9. 二分查找 HDOJ 2141 Can you find it?

    题目传送门 /* 题意:给出一个数,问是否有ai + bj + ck == x 二分查找:首先计算sum[l] = a[i] + b[j],对于q,枚举ck,查找是否有sum + ck == x */ ...

随机推荐

  1. TypeError: not enough arguments for format string

    到一个问题,表示100% 的时候,出现这个问题. 因为python语法会认为是你需要转移符,这个时候你可以选择100%% 来表示

  2. filter 以及 orderBy的使用

    filter用于关键字过滤操作,orderBy用于排序操作,运行界面如下: 点击标题Name与Email实现排序功能,输入框中输入关键字进行过滤,同时实现根据关键字进行过滤后进行排序操作: ng-re ...

  3. java.lang.OutOfMemoryError: unable to create new native thread(转)

    解决 - java.lang.OutOfMemoryError: unable to create new native thread 工作中碰到过这个问题好几次了,觉得有必要总结一下,所以有了这篇文 ...

  4. 【转】CTS tests 4.2_r4

    原文网址:http://www.xuebuyuan.com/1722006.html Precondition: 1.Get android sdk 2.Set adb to environment ...

  5. mysqli connect database and print

    <?php $connect = mysqli_connect('localhost','root','','intertrading') or die('Unale to connect'); ...

  6. 独立写作(A or B)

    开头:On contemporary society(一般的背景)/ With the advent of the technologically advanced society (the info ...

  7. OpenStackCLI调试及术语识记

    1,Project are organizational units in the cloud,and are also known as tenants or accounts.Each user ...

  8. setOpaque(true);设置控件不透明

    setOpaque(true);设置控件不透明setOpaque(false);设置控件透明

  9. 04747_Java语言程序设计(一)_第6章_图形界面设计(二)

    例6.1声明一个面板子类,面板子类对象有3个选择框. class Panel1 extends JPanel { JCheckBox box1, box2, box3; Panel1() { box1 ...

  10. goahead webserver源码分析

    1.一个txt文本架构图 main() | |--websOpenServer() |             |-- websOpenListen() |                       ...