• 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:
    ", 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;
    }
    By: GadyPu 博客地址:http://www.cnblogs.com/GadyPu/ 转载请说明
  • 相关阅读:
    【2019.7.10】树上差分 杂[LCA 倍增][树上差分 点差分 边差分]
    【luogu4145】 上帝造题的七分钟2 / 花神游历各国 [线段树]
    【luogu1198】 [JSOI2008]最大数 [线段树]
    【luogu2783】 有机化学之神偶尔会做作弊 [tarjan 缩点][LCA]
    【luogu3388】 【模板】割点(割顶)[tarjan 割点]
    【luogu2272】 [ZJOI2007]最大半连通子图 [tarjan 缩点][拓扑排序]
    【luogu2194】HXY烧情侣 [tarjan 缩点]
    【luogu3627】 [APIO2009]抢掠计划 [tarjan 缩点][最短路]
    【luogu3398】 仓鼠找sugar [LCA 倍增]
    【luogu2746】 [USACO5.3]校园网Network of Schools [tarjan 缩点]
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4771801.html
Copyright © 2020-2023  润新知