zoukankan      html  css  js  c++  java
  • hdu 2141 Can you find it? 夜

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

    二分

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<map>
    #include<vector>
    #include<stack>
    #include<set>
    #include<map>
    #include<queue>
    #include<deque>
    #include<algorithm>
    #include<cmath>
    #define LL long long
    //#pragma comment(linker, "/STACK:1024000000,1024000000")
    using namespace std;
    const double eps=1e-9;
    const int INF=0x3f3f3f3f;
    const double FINF=1e9;
    const int N=1005;
    LL a[N],b[N],c[N];
    LL k[N*N];
    bool binsearch(LL w,int l,int r)
    {
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(k[mid]==w)
            return true;
            if(k[mid]<w)
            l=mid+1;
            else
            r=mid-1;
        }
        return false;
    }
    int main()
    {
        //freopen("data.in","r",stdin);
        //freopen("data.out","w",stdout);
        int T=0;
        int A,B,C;
        while(scanf("%d %d %d",&A,&B,&C)!=EOF)
        {
            ++T;
            for(int i=0;i<A;++i)
            scanf("%I64d",&a[i]);
            for(int i=0;i<B;++i)
            scanf("%I64d",&b[i]);
            for(int i=0;i<C;++i)
            scanf("%I64d",&c[i]);
            int I=0;
            for(int i=0;i<A;++i)
            for(int j=0;j<B;++j)
            k[I++]=a[i]+b[j];
            sort(k,k+I);
            printf("Case %d:\n",T);
            int q;
            scanf("%d",&q);
            while(q--)
            {
                LL s;
                scanf("%I64d",&s);
                int l;
                for(l=0;l<C;++l)
                {
                    if(binsearch(s-c[l],0,I-1))
                    break;
                }
                if(l<C)
                printf("YES\n");
                else
                printf("NO\n");
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    C#之设计模式
    C#之索引器
    C#基础强化-继承与多态
    C#基础强化-进程操作
    WKWebView与JavaScript交互基础
    HTML之JS学习
    HTML之CSS学习
    HTML学习
    玩诈欺的小杉
    最大异或和
  • 原文地址:https://www.cnblogs.com/liulangye/p/2924183.html
Copyright © 2011-2022 走看看