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. 【转】「Chris Richardson 微服务系列」微服务架构的优势与不足

    Posted on 2016年5月4日 编者的话|本文来自 Nginx 官方博客,是微服务系列文章的第一篇,主要探讨了传统的单体式应用的不足,以及微服务架构的优势与挑战. 作者介绍:Chris Ric ...

  2. Mac下更改Mysql5.7的默认编码为utf8

    Mac上从官方安装完Mysql5.7后,有一部分的字符集默认为latin1,而非utf8,为避免乱码的产生,本文介绍将所有字符集设置为utf8 查看当前字符集编码 show variables lik ...

  3. BZOJ 1011--[HNOI2008]遥远的行星(乱搞)

    1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 5684  Solved ...

  4. 学习人工智还死拽着Python不放?大牛都在用Anaconda5.2.0

    前言 最近有很多的小白想学习人工智能,可是呢?依旧用Python在学习.我说大哥们,现在都什么年代了,还在把那个当宝一样拽着死死不放吗?懂的人都在用Anaconda5.2.0,里面的功能可强大多了,里 ...

  5. Apache Roller 5.0.3 XXE漏洞分析

    下载5.0.2的版本来分析 5.0.2的war包地址 http://archive.apache.org/dist/roller/roller-5/v5.0.2/bin/roller-weblogge ...

  6. JS 跨域认识及如何解决

    什么是跨域 指的是浏览器不允许javascrip脚本向其他域名发起ajax请求. 跨域的各种情况判定 URL 说明 是否允许通信 http://www.a.com/a.js http://www.a. ...

  7. Vue2.5开发去哪儿网App 第五章笔记 下

    1. 多个元素或组件的过渡 多个元素的过渡: <style> .v-enter,.v-leace-to{ opacity: 0; } .v-enter-active,.v-leave-ac ...

  8. (转)python中的selectors模块

    原文:https://www.cnblogs.com/yinheyi/p/8127871.html https://www.rddoc.com/doc/Python/3.6.0/zh/library/ ...

  9. godaddy 问题

    1. 域名被锁,打电话咨询后.说发送被锁的域名到: change@secureserver.net 去解锁.

  10. Azure Redis 缓存使用注意事项与排查问题文档整理

    StackExchange.Redis 使用名为 synctimeout 的配置设置进行同步操作,该设置的默认值为 1000 毫秒. 如果同步调用未在规定时间内完成,StackExchange.Red ...