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. window.open新打开窗口与新开标签页

    最近在使用window.open时忽略了一个细节问题:window.open新打开一个窗口,但是有时却是新打开一个窗口有时打开一个新标签页.虽然对一般的需求来说,这个两种情况都无所谓,但是对于那种有强 ...

  2. 【文文殿下】【洛谷】分治NTT模板

    题解 可以计算每一项对后面几项的贡献,然后考虑后面每一项,发现这是一个卷积,直接暴力NTT就行了,发现它是一个有后效性的,我们选择使用CDQ分治. Tips:不能像通常CDQ分治一样直接 每次递归两边 ...

  3. BitArray源码解析

    BitArray是C# System.Collections内置的集合,用于帮助进行位运算. BitArray的使用示例 // 创建两个大小为 8 的点阵列 BitArray ba1 = new Bi ...

  4. 初识MQ

    [参考文章]:到底什么时候该使用MQ? 1. 什么是MQ? 消息队列(Message Quene)是一种跨进程的通信机制,用于上下游传递消息. MQ是一种非常常见的上下游“逻辑解耦+物理解耦”的消息通 ...

  5. python3.6使用f-string来格式化字符串

    这里的f-string指的是以f或F修饰的字符串,在字符串中使用{}来替换变量,表达式和支持各种格式的输出.详细的格式化定义可以看官方文档 >>> a, b = 30, 20 > ...

  6. [原创]K8正方系统密码解密工具

    工具: K8_zfsoftDecode编译: 自己查壳组织: K8搞基大队[K8team]作者: K8拉登哥哥博客: http://qqhack8.blog.163.com发布: 2015/8/1 1 ...

  7. Spring Boot 中使用 Jedis 及 Lettuce的对比

    首先,同样的程序,采用不同方式的Redis连接方式. defautl : 默认,0配置 ,也就是走的是 lettuce 单通道方式.   端口:8081 jedis : 使用Jedis 连接池.    ...

  8. canvars 画花

    index.html <!DOCTYPE html><html><head> <title>旋转的花</title> <meta ch ...

  9. Gen对于数组Array的处理

    举个例子,如下: public void t() { String[][] a = new String[][] { { "x", "y" } }; Strin ...

  10. 使用 GMap.NET 实现添加标注、移动标注功能。(WPF版)

    前言 在WPF嵌入地图,有两种方式: 浏览器方式:控件方式. 1)浏览器方式就是使用浏览器控件WebBrowser,设置好网址就行了.这种方式与地图的交互不太直接,需要懂html.javascript ...