题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=2141

Can you find it?

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

简单的哈希判重。。

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
using std::map;
using std::abs;
using std::find;
using std::pair;
using std::vector;
using std::multimap;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr, val) memset(arr, val, sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = 500007;
const int INF = 0x3f3f3f3f;
struct Hash_Set {
int tot, num[N], head[N], next[N];
inline void init() {
tot = 0, cls(head, -1);
}
inline void insert(int val) {
int u = abs(val) % N;
num[tot] = val, next[tot] = head[u], head[u] = tot++;
}
inline bool find(int val) {
int u = abs(val) % N;
for (int i = head[u]; ~i; i = next[i]) {
if (num[i] == val) return true;
}
return false;
}
}hash;
int A[3][510];
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int l, n, m, t, v, k = 1;
while (~scanf("%d %d %d", &l, &n, &m)) {
hash.init();
rep(i, l) scanf("%d", &A[0][i]);
rep(i, n) scanf("%d", &A[1][i]);
rep(i, m) scanf("%d", &A[2][i]);
rep(i, l) {
rep(j, n) {
int val = A[0][i] + A[1][j];
hash.insert(val);
}
}
scanf("%d", &t);
printf("Case %d:\n", k++);
while (t--) {
bool f = false;
scanf("%d", &v);
rep(i, m) {
if (hash.find(v - A[2][i])) f = true;
}
puts(f ? "YES" : "NO");
}
}
return 0;
}

hdu 2141 Can you find it?的更多相关文章

  1. hdu 2141 (二分)

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

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

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

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

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

  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? (二分法)

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

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

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

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

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

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

随机推荐

  1. Flex 使用列表和表格

    Flex 设计了不同的控件来实现列表和表格,不仅能够将数据显示在表格和列表中,还可以实现对数据进行操纵,修改等更加强大的功能. 与列表和表格相关的控件如下所示: 列表控件(List Control): ...

  2. 【测试】通过RMAN联机全库备份,包括控制文件,归档日志文件,备份成功后,删除已备份的归档日志。

    RMAN是一个很方便很好用的备份,恢复,还原的一个工具,做这个小测试其实只有一个RMAN语句就完全解决了这么大的需求: RMAN> backup as backupset full databa ...

  3. 互联网+医疗(FW)

    http://www.yn.xinhuanet.com/health/2015-06/05/c_134300133.htm 互联网+医疗 让合适的病人找合适的医生 www.yn.xinhuanet.c ...

  4. Json.net实现方便的Json转C#(dynamic动态类型)对象

    以前需要将一段json字符串转换为C#对象时,一般都是定义一个与之对应的实体类来接收.这样做有一个很大的缺点,就是当字符串特别长,属性特别多,又有嵌套时,手敲这个实体类就非常痛苦. 比如之前做的一个接 ...

  5. 理解python可变类型vs不可变类型,深拷贝vs浅拷贝

    核心提示: 可变类型 Vs 不可变类型 可变类型(mutable):列表,字典 不可变类型(unmutable):数字,字符串,元组 这里的可变不可变,是指内存中的那块内容(value)是否可以被改变 ...

  6. linux 下安装 搭建 svn服务器

    1.下载svn http://subversion.apache.org/download 下载完成后解压,执行 ./configure --prefix=/usr/svn 提示 configure: ...

  7. c++ builder TListView控件按字符串排序(根据网上代码亲测ok)

    //--------------------------------------------------------------------------- /* 首先将一个列表框控件安放在Form上, ...

  8. SVN创建资源与分支详解

    创建分支的意义: 简单说,分支就是用于区分开发版本与当前发布版本的. 1. 主干负责新功能的开发 2..分支负责修正当前发布版本的bug(对于可以放入下个发布版本的改进性bug可以直接在主干上开发) ...

  9. Android IOS WebRTC 音视频开发总结(五五)-- 音视频通讯中的抗丢包与带宽自适应原理

    本文主要分析webrtc中的抗丢包与带宽自适应原理,文章来自博客园RTC.Blacker,欢迎关注微信公众号blacker,更多详见www.rtc.help 文章内容主要来自中国电信北京研究院丁博士在 ...

  10. Android IOS WebRTC 音视频开发总结(七)-- 基于浏览器的开发

    前面写的一系列总结都是讲webrtc如何下载,编译,开发的,有些人可能有点云里雾里了,WEBRTC不是用来搞跨浏览器开发的吗,怎么我讲的这些跟浏览器扯不上任何关系,其实看看下面这个架构图,你就明白了, ...