hdu 2141 Can you find it?
题目连接
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?的更多相关文章
- hdu 2141 (二分)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 Can you find it? Time Limit: 10000/3000 MS (Java/O ...
- hdu 2141 Can you find it?(二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 题目大意:查找是否又满足条件的x值. 这里简单介绍一个小算法,二分查找. /* x^2+6*x- ...
- HDU 2141 Can you find it? (二分)
题目链接: Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/ ...
- hdu 2141:Can you find it?(数据结构,二分查找)
Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others ...
- hdu 2141 Can you find it? (二分法)
Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others ...
- Can you find it?(hdu 2141 二分查找)
Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 检测zookeeper和kafka是否正常
cd $(dirname $) source ~/.bash_profile count_zoo=`ps -ef | grep "config/zookeeper.properties&qu ...
- oracle 清除当前用户的回收站
--清除当前用户的回收站:purge recyclebin; --删除表数据truncate table --查看当前用户回收站select * from user_recyclebin t;
- 学习总结 for循环--冒泡排序
//输入N个人的分数,按从高到低进行排序 Console.Write("请输入人数"); int n = int.Parse(Console.ReadLine()); int[] ...
- ffmpeg视频格式转换(Java)
命令: 高品质: ffmpeg -i E:\input\a.wmv -ab 128 -acodec libmp3lame -ac 1 -ar 22050 -r 29.97 -qscale 4 -y E ...
- No.001 Two Sum
Two Sum Total Accepted: 262258 Total Submissions: 1048169 Difficulty: Easy Given an array of integer ...
- IE11-IE不再任性了-关于attachEvent
今天解决了一个IE11的兼容问题,关于attachEvent的. 控件是ActiveX的,需要监听一个控件相关的事件.蓦然发现attachEvent在IE11不支持了...attachEvent不是I ...
- 智能指针(三):unique_ptr使用简介
我们知道auto_ptr通过复制构造或者通过=赋值后,原来的auto_ptr对象就报废了.所有权转移到新的对象中去了.而通过shared_ptr可以让多个智能指针对象同时拥有某一块内存的访问权.但假如 ...
- leetcode279. Perfect Squares
learn from DP class Solution { public: int numSquares(int n) { if(n<=0)return 0; int * dp = new i ...
- poj3274 哈希
这题终于让我AC了,其过程之艰辛我不想再回忆了,看了各种代码,一定要注意指针空和非空的问题,再一个要注意边界. #include <stdio.h> #include <string ...
- com.google.inject.CreationException: Guice creation errors
错误的原因:xml文件中方法名重复或错误