http://acm.hdu.edu.cn/showproblem.php?pid=2141
分析:C=X-A-B,因为数字太大不能直接用数组保存,用二分查找加快速率
类似:hdu 2578(注意数据包含0)
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int NM=505;
__int64 a[NM],b[NM],c[NM],num[NM*NM];
int main()
{
__int64 L,N,M,i,j,flag,t,n,ans,mid,low,high,T;
ans=1;
while(scanf("%I64d%I64d%I64d",&L,&N,&M)!=EOF)
{
printf("Case %d:\n",ans++);
for(i=1;i<=L;i++)
scanf("%I64d",&a[i]);
for(i=1;i<=N;i++)
scanf("%I64d",&b[i]);
for(i=1;i<=M;i++)
scanf("%I64d",&c[i]);
t=1;
for(i=1;i<=L;i++)
for(j=1;j<=N;j++)
num[t++]=a[i]+b[j];;
sort(num+1,num+L*N); //
scanf("%I64d",&T);
while(T--)
{
scanf("%I64d",&n);
for(i=1;i<=M;i++)
{
t=n-c[i];flag=0;
low=1,high=L*N;
while(low<=high)
{
mid=(low+high)/2;
if(t==num[mid])
{flag=1;break;}
else if(t<num[mid])
high=mid-1;
else
low=mid+1;
}
if(flag) break;
}
if(flag)
printf("YES\n");
else printf("NO\n");
}
}
return 0;

1万+

被折叠的 条评论
为什么被折叠?



