题目链接:

Can you find it?

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

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
 

题目大意:

多组数据输入

第一行是三个序列各自元素的个数

第2,3,4是三个序列

第4行是x的个数

下面的x行是多种情况的x值

分析:

三个序列三个数组,把前面两个数组组合为一个数组

比如1 2 3,1 2 3,这两个序列组合为一个数组‘

1+1,1+2,1+3,2+1,2+2,2+3,3+1,3+2,3+3,

计算一下就是

2,3,4,3,4,5,4,5,6,有重复的但是不用去掉,称这个序列为t

然后与第三个序列组合

1 ,2,3,(第三个序列)

然后将t序列升序排序,t与第三个序列组合的时候,t序列采用二分寻找数据

注意点:

1.不能采用set去重,不然会超内存(第一次遇到超内存,好激动啊啊啊啊啊)

2.对t序列不能采用for循环寻找数据,要采用排好序之后再二分查找数据,不然会超时

代码如下:

#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
return a<b;
}
int main()
{
int n1,n2,n3,n=;
while(~scanf("%d %d %d",&n1,&n2,&n3))
{
int a[n1],b[n2],c[n3];
for(int i=; i<n1; i++)
{
scanf("%d",&a[i]);
}
for(int j=; j<n2; j++)
{
scanf("%d",&b[j]);
}
for(int k=; k<n3; k++)
{
scanf("%d",&c[k]);
}
int xn;
int t[n1*n2];
scanf("%d",&xn);
int x[xn];
for(int i=; i<xn; i++)
{
scanf("%d",&x[i]);
}
int y=;
for(int i=; i<n1; i++)
{
for(int j=; j<n2; j++)
{
int z=a[i]+b[j];
t[y]=z;
y++;
}
}
sort(t,t+(n1*n2),cmp);
printf("Case %d:\n",n);
for(int i=; i<xn; i++)
{
int f=;
for(int k=;k<n3;k++)
{
int l=,h=n1*n2-;
while(l<=h)
{
int mid=(l+h)/; if(t[mid]==x[i]-c[k])
{
f=;
break;
}else if(t[mid]>x[i]-c[k])
{
h=mid-;
}else if(t[mid]<x[i]-c[k])
{
l=mid+;
}
}
if(f==)
break;
}
if(f==)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
n++;
}
return ;
}

哈哈哈哈哈哈哈哈哈哈

今天真的是超级开心

不准吐槽。。。。。

。。。。。。。。。。

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

  1. HDU 2141 Can you find it? [二分]

    Can you find it? Give you three sequences of numbers A, B, C, then we give you a number X. Now you n ...

  2. C - 啥~ 渣渣也想找玩数字 HDU - 2141(有序序列枚举 + 二分优化查找)

    题目描述 可爱的演演又来了,这次他想问渣渣一题... 如果给你三个数列 A[],B[],C[],请问对于给定的数字 X,能否从这三个数列中各选一个,使得A[i]+B[j]+C[k]=X? 输入 多组数 ...

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

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

  4. hdu 2141 (二分)

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

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

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

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

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

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

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

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

随机推荐

  1. AngularJS之过滤器

    AnularJS的过滤器用来格式化需要展示给用户的数据,有很多实用的内置过滤器,也可以自己编写. 在HTML中的模板绑定符号{{ }}内通过|符号来调用过滤器.例如,假设我们希望将字符串转换成大写,可 ...

  2. HTML5 MutationObserver检测页面劫持

    好久没写博客了,业务一直在变化,陆陆续续的做了很多web app,被业务流淹没就很少有机会去反思,前端技术发展如此之快,常常有种不学则退的恐慌,一种技术还没吃透就涌出新的技术,然后一波人又打着各种旗帜 ...

  3. css绘制进度条,持续转动的进度条

    //只有 progress pregress-par bar,进度条不会转, //增加 active 这个类,进度条会转, //html结构 <div class='progress activ ...

  4. js下载文件

    本文的前提是:后台给的是一个可以下载的url的情况下的下载: 怎样的文件url才能触发浏览器的下载行为?(转自SF) 能触发浏览器下载的url有两类: response header中指定了Conte ...

  5. opencv3.2.0图像处理之均值滤波blur API函数

    ##.均值滤波:blur函数 ##函数原型 : ,-),int borderType=BORDER_DEFAULT) (参数详解同boxFilter函数) /**********新建Qt控制台程序** ...

  6. 网络I/O模型--02阻塞模式(多线程)

    当服务器收到客户端 X 的请求后(读取到所有请求数据后),将这个请求送入一个独立线程进行处理,然后主线程继续接收客户端 Y 的请求. 客户端一侧也可以使用一个子线程和服务器端进行通信.这样客户端主线程 ...

  7. Android MVP Plugin,一键完成MVP结构代码编写

    推荐一个Gradle的学习系列,Gradle相关的知识一直很匮乏,难得发现一个不错的系列: http://www.cnblogs.com/davenkin/p/gradle-learning-1.ht ...

  8. flutter开发中常用的dart插件

    flutter插件官网地址:https://pub.dartlang.org/packages/ 1. image_picker 一个可以从图库选择图片,并可以用相机拍摄新照片的flutter插件 2 ...

  9. iframe内存释放

    Ext 核心开发人员Jack的回答是,TabPanelItem在关闭时并不会对自定义到tab中的元素做特殊处理,这部分工作必须在控件外来完成.另一方面, 相关资料称IE在iframe元素的回收方面存在 ...

  10. 创建和修改 ExpressRoute 线路的对等互连

    本文将指导你执行相关步骤,以便使用 Azure 门户和 Resource Manager 部署模型创建和管理 ExpressRoute 线路的路由配置. 配置先决条件 在开始配置之前,请务必查看先决条 ...