Can you find it?

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

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
 
题意:给你三组数据,每组有L,N,M个数,每组取一个相加,问在他们的和数组里有没有x这个数?;
 
思路:数组+二分。。。。。
 
 
详见代码:
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std; int cmp(int x,int y)
{
return x<y;
}
__int64 num[];
int main()
{
int S,ans,i,j,k,temp,t=;
int L,N,M,a[],b[],c[],p; int left,right,middle;
while(scanf("%d%d%d",&L,&N,&M)!=EOF)
{
// memset(num,0,sizeof(num));
for(i=;i<L;i++)
{
scanf("%d",&a[i]);
}
// sort(a,a+L,cmp);
for(i=;i<N;i++)
{
scanf("%d",&b[i]);
}
// sort(b,b+N,cmp);
for(i=;i<M;i++)
{
scanf("%d",&c[i]);
}
// sort(c,c+M,cmp);
ans=;
for(i=;i<L;i++)
for(j=;j<N;j++)
{
num[ans++]=a[i]+b[j];
}
sort(num,num+ans,cmp);
printf("Case %d:\n",t++);
scanf("%d",&S);
while(S--)//for(i=0;i<S;i++)写成这样,,,那怪超时。。。顿时郁闷了!
{
temp=;
scanf("%d",&p);
for(i=;i<M;i++)
{
if(num[]<=p-c[i]&&p-c[i]<=num[ans-])
{
left=;
right=ans-; while(right-left>=)
{
middle=(left+right)/; if(num[middle]>p-c[i])
{
right=middle-;
}
else if(num[middle]<p-c[i])
{
left=middle+;
}
else
{temp=;break;}
} }
else
temp=;
if(temp)
break;
}
if(temp)
printf("YES\n");
else
printf("NO\n");
}
}
return ;
}
/*
3 3 3
1 2 3
1 2 3
1 2 3
11
4
1
10
9
8
7
6
5
3
2
11
*/

Can you find it?(数组+二分hdu2141)的更多相关文章

  1. POJ 2828 Buy Tickets (线段树 or 树状数组+二分)

    题目链接:http://poj.org/problem?id=2828 题意就是给你n个人,然后每个人按顺序插队,问你最终的顺序是怎么样的. 反过来做就很容易了,从最后一个人开始推,最后一个人位置很容 ...

  2. BZOJ 3230: 相似子串( RMQ + 后缀数组 + 二分 )

    二分查找求出k大串, 然后正反做后缀数组, RMQ求LCP, 时间复杂度O(NlogN+logN) -------------------------------------------------- ...

  3. BZOJ_2946_[Poi2000]公共串_后缀数组+二分答案

    BZOJ_2946_[Poi2000]公共串_后缀数组+二分答案 Description          给出几个由小写字母构成的单词,求它们最长的公共子串的长度. 任务: l        读入单 ...

  4. TZOJ 4602 高桥和低桥(二分或树状数组+二分)

    描述 有个脑筋急转弯是这样的:有距离很近的一高一低两座桥,两次洪水之后高桥被淹了两次,低桥却只被淹了一次,为什么?答案是:因为低桥太低了,第一次洪水退去之后水位依然在低桥之上,所以不算“淹了两次”.举 ...

  5. POJ 2182 Lost Cows 【树状数组+二分】

    题目链接:http://poj.org/problem?id=2182 Lost Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  6. 【bzoj4310】跳蚤 后缀数组+二分

    题目描述 很久很久以前,森林里住着一群跳蚤.一天,跳蚤国王得到了一个神秘的字符串,它想进行研究. 首先,他会把串分成不超过 k 个子串,然后对于每个子串 S,他会从S的所有子串中选择字典序最大的那一个 ...

  7. 树状数组+二分||线段树 HDOJ 5493 Queue

    题目传送门 题意:已知每个人的独一无二的身高以及排在他前面或者后面比他高的人数,问身高字典序最小的排法 分析:首先对身高从矮到高排序,那么可以知道每个人有多少人的身高比他高,那么取较小值(k[i], ...

  8. BZOJ 1717 [USACO06DEC] Milk Patterns (后缀数组+二分)

    题目大意:求可重叠的相同子串数量至少是K的子串最长长度 洛谷传送门 依然是后缀数组+二分,先用后缀数组处理出height 每次二分出一个长度x,然后去验证,在排序的后缀串集合里,有没有连续数量多于K个 ...

  9. POJ 1743 [USACO5.1] Musical Theme (后缀数组+二分)

    洛谷P2743传送门 题目大意:给你一个序列,求其中最长的一对相似等长子串 一对合法的相似子串被定义为: 1.任意一个子串长度都大于等于5 2.不能有重叠部分 3.其中一个子串可以在全部+/-某个值后 ...

随机推荐

  1. 企业项目开发--cookie(3)

    此文已由作者赵计刚授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 2.2.3.AdminController   1 package com.xxx.web.admin;   ...

  2. iOS-项目开发1

    FFPageControl 由于UIPageControl不能设置图片,而在实际开发中又经常遇到需要使用图片的情况,故仿照系统UIPageControl,重写了FFPageControl,以支持图片的 ...

  3. 【入门推荐】SQL注入进行WebShell渗透测试的基础概览

    作者:zero 本文为SQL基本注入的进阶文章,如有任何疑问请查看: SQL基本注入演示:https://www.cnblogs.com/anbus/p/10082452.html 导语: 利用SQL ...

  4. 为ElasticSearch添加HTTP基本认证

    ES的HTTP连接没有提供任何的权限控制措施,一旦部署在公共网络就容易有数据泄露的风险,尤其是加上类似elasticsearch-head这样友好的前端界面,简直让你的数据瞬间裸奔在黑客的眼皮底下.项 ...

  5. zookeeper单机版安装

    ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一致性服务的软件,提供的功 ...

  6. Mac OSX配置XAMP虚拟主机

    在前端工作中,有时候需要配置下环境,这篇文章主要是记录了在wamp中配置虚拟主机 首先需要下载wamp软件和navicat数据库管理软件进行管理,下面默认已经下载好所需软件.并且打开服务. 第一步:把 ...

  7. 【xsy3355】图 思维

    题目大意:给你一个n个点m条无向边的图,问这个图是否能够: 1,被四染色(用四种颜色给图染色,且相邻点颜色不同). 2,找出一个奇环,满足在原图中去掉这个奇环后每个点依然相邻. 请输出1或者2中的任意 ...

  8. Centos 7 开启BBR

    # 升级内核 rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org rpm -Uvh http://www.elrepo.org/elr ...

  9. 课程二(Improving Deep Neural Networks: Hyperparameter tuning, Regularization and Optimization),第二周(Optimization algorithms) —— 2.Programming assignments:Optimization

    Optimization Welcome to the optimization's programming assignment of the hyper-parameters tuning spe ...

  10. Hadoop和Apache Spark的异同

    谈到大数据,相信大家对Hadoop和Apache Spark这两个名字并不陌生.但我们往往对它们的理解只是提留在字面上,并没有对它们进行深入的思考,下面不妨跟我一块看下它们究竟有什么异同. 1.解决问 ...