• HDU 2141 Can you find it?


    题意:从序列A,B,C中分别选一个数,有无可能等于X。

    分析:

    1、枚举A中所有数,由此可知X-Ai。

    2、统计记录Bi+Ci的所有可能性

    3、在 这所有可能性里二分找X-Ai

    #pragma comment(linker, "/STACK:102400000, 102400000")
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<cmath>
    #include<iostream>
    #include<sstream>
    #include<iterator>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    #include<deque>
    #include<queue>
    #include<list>
    #define Min(a, b) ((a < b) ? a : b)
    #define Max(a, b) ((a < b) ? b : a)
    typedef long long ll;
    typedef unsigned long long llu;
    const int INT_INF = 0x3f3f3f3f;
    const int INT_M_INF = 0x7f7f7f7f;
    const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
    const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
    const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
    const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
    const int MOD = 1e9 + 7;
    const double pi = acos(-1.0);
    const double eps = 1e-8;
    const int MAXN = 500 + 10;
    const int MAXT = 250000 + 10;
    using namespace std;
    int sum[MAXT];
    int a[MAXN];
    int b[MAXN];
    int c[MAXN];
    int cnt;
    bool solve(int x){
        int l = 0, r = cnt - 1;
        while(l <= r){
            int mid = l + (r - l) / 2;
            if(sum[mid] == x) return true;
            else if(sum[mid] < x) l = mid + 1;
            else r = mid - 1;
        }
        return false;
    }
    int main(){
        int L, M, N;
        int kase = 0;
        while(scanf("%d%d%d", &L, &M, &N) == 3){
            memset(sum, 0, sizeof sum);
            memset(a, 0, sizeof a);
            memset(b, 0, sizeof b);
            memset(c, 0, sizeof c);
            for(int i = 0; i < L; ++i){
                scanf("%d", &a[i]);
            }
            for(int i = 0; i < M; ++i){
                scanf("%d", &b[i]);
            }
            for(int i = 0; i < N; ++i){
                scanf("%d", &c[i]);
            }
            cnt = 0;
            for(int i = 0; i < M; ++i){
                for(int j = 0; j < N; ++j){
                    sum[cnt++] = b[i] + c[j];
                }
            }
            sort(sum, sum + cnt);
            int S;
            scanf("%d", &S);
            printf("Case %d:\n", ++kase);
            while(S--){
                bool ok = false;
                int x;
                scanf("%d", &x);
                for(int i = 0; i < L; ++i){
                    int t = x - a[i];
                    if(solve(t)){
                        printf("YES\n");
                        ok = true;
                        break;
                    }
                }
                if(!ok) printf("NO\n");
            }
        }
        return 0;
    }
  • 相关阅读:
    设计模式之装饰模式
    SpringAOP 失效解决方案、Spring事务失效
    Jmeter测试出现端口占用情况
    ElasticSearch创建动态索引
    Zuul + Ribbon 脱离Eureka完成负载均衡+重试机制
    TCP的三次握手与四次挥手笔记
    Java中的阻塞队列
    Jmeter5.1——聚合报告参数分析
    SpringCloud"灰度部署"——动态刷新网关配置
    JVM学习笔记——类加载过程
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/6271102.html
Copyright © 2020-2023  润新知