zoukankan      html  css  js  c++  java
  • 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 need to calculate if you can find the three numbers Ai, Bj, Ck, which satisfy the formula Ai+Bj+Ck = X.

    你以为我是因为被$world final$打击到了而在做水题吗?
    没错我就是在做水题.........mhy12345课件上的.....
    每个询问枚举$A$然后二分$B+C$
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    const int N=505,M=N*N;
    inline int read(){
        char c=getchar();int x=0,f=1;
        while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
        return x*f;
    }
    int a[N],b[N],c[N];
    int w[M],n;
    int Bin(int v){//printf("Bin %d
    ",v);
        int l=1,r=n;
        while(l<=r){
            int mid=(l+r)>>1;//printf("%d %d %d  %d %d
    ",l,r,mid,w[mid],v);
            if(w[mid]==v) return mid;
            else if(v<w[mid]) r=mid-1;
            else l=mid+1;
        }
        return 0;
    }
    int main(){
        freopen("in","r",stdin);
        int cas=0;
        while(scanf("%d%d%d",a,b,c)!=EOF){
            printf("Case %d:
    ",++cas);
            for(int i=1;i<=(*a);i++) a[i]=read();
            for(int i=1;i<=(*b);i++) b[i]=read();
            for(int i=1;i<=(*c);i++) c[i]=read();
            n=0;
            for(int i=1;i<=(*b);i++)
                for(int j=1;j<=(*c);j++) w[++n]=b[i]+c[j];
            sort(w+1,w+1+n);
            int Q=read();
            while(Q--){
                int x=read(),flag=0;
                for(int i=1;i<=(*a);i++) if(Bin(x-a[i])) {flag=1;break;}
                if(flag) puts("YES");
                else puts("NO");
            }
        }
    }
     
     
     
  • 相关阅读:
    linux命令(一)
    Maven 打包不同环境
    Spring动态代理
    Spring MVC controller方法和jstl
    logback的使用
    从文本导入导出
    将临时全局表中的符合字段导入test数据库中
    将上传的新表导入临时全局表中
    建立临时表导入
    查询统计表以及删除表
  • 原文地址:https://www.cnblogs.com/candy99/p/6430426.html
Copyright © 2011-2022 走看看