题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2141

题意:叫你找三个数,使得这三个数的值为X,如果找得到就输出YES否则输出NO,注意两个32位数相加会爆int

 #include<cstdio>
#include<algorithm>
using namespace std;
#define FFC(i,a,b) for(int i=a;i<=b;i++)
int L,N,M,t,ic=,x,l,r,mid,cnt;
long long a[],b[],c[],tmp[];
int lowb(long long *a,int x,int len){for(l=,r=len;l<=r;)if(a[mid=l+((r-l)>>)]>=x)r=mid-;else l=mid+;return l;}
int main(){
while(~scanf("%d%d%d",&L,&N,&M)){
printf("Case %d:\n",ic++);
FFC(i,,L)scanf("%lld",&a[i]);
FFC(i,,N)scanf("%lld",&b[i]);
FFC(i,,M)scanf("%lld",&c[i]);
cnt=;
FFC(i,,L)FFC(j,,N)tmp[++cnt]=a[i]+b[j];
sort(tmp+,tmp++cnt);
sort(c+,c++M);
scanf("%d",&t);
while(t--){
scanf("%d",&x);
if(x<c[]){puts("NO");continue;}
int fg=;
FFC(i,,M)if(tmp[lowb(tmp,x-c[i],cnt)]==x-c[i]){fg=;break;}
if(fg)puts("YES");
else puts("NO");
}
}
return ;
}
05-11 09:29