hdu_2141_Can you find it?(二分)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2141
题意:叫你找三个数,使得这三个数的值为X,如果找得到就输出YES否则输出NO,注意两个32位数相加会爆int
1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 #define FFC(i,a,b) for(int i=a;i<=b;i++) 5 int L,N,M,t,ic=1,x,l,r,mid,cnt; 6 long long a[510],b[510],c[510],tmp[250010]; 7 int lowb(long long *a,int x,int len){for(l=1,r=len;l<=r;)if(a[mid=l+((r-l)>>1)]>=x)r=mid-1;else l=mid+1;return l;} 8 int main(){ 9 while(~scanf("%d%d%d",&L,&N,&M)){ 10 printf("Case %d:\n",ic++); 11 FFC(i,1,L)scanf("%lld",&a[i]); 12 FFC(i,1,N)scanf("%lld",&b[i]); 13 FFC(i,1,M)scanf("%lld",&c[i]); 14 cnt=0; 15 FFC(i,1,L)FFC(j,1,N)tmp[++cnt]=a[i]+b[j]; 16 sort(tmp+1,tmp+1+cnt); 17 sort(c+1,c+1+M); 18 scanf("%d",&t); 19 while(t--){ 20 scanf("%d",&x); 21 if(x<c[1]){puts("NO");continue;} 22 int fg=0; 23 FFC(i,1,M)if(tmp[lowb(tmp,x-c[i],cnt)]==x-c[i]){fg=1;break;} 24 if(fg)puts("YES"); 25 else puts("NO"); 26 } 27 } 28 return 0; 29 }