标签:
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others)
Total Submission(s): 21485 Accepted Submission(s): 5446
#include<iostream> #include<algorithm> int a[510], b[510], c[510],sum[250010]; using namespace std; int f(int x,int z,int y)//二分注意加一 { int mid; while(z<=y) { mid=(z+y)/2; if(sum[mid]==x) return 1; else if(sum[mid]>x) y=mid-1; else if(sum[mid]<x) z=mid+1; } return 0; } int main() { int l,m,n,z,i,j,t,k=1; while(scanf("%d%d%d", &l, &m, &n)!=EOF) { for(i=0;i<l;i++)scanf("%d",&a[i]);//一开始l,m,n写乱了,WA了好几遍,玛德智障。。。 for(i=0;i<m;i++)scanf("%d",&b[i]); for(i=0;i<n;i++)scanf("%d",&c[i]); for(i=0;i<l;i++) for(j=0;j<m;j++) sum[i*m+j]=a[i]+b[j]; sort(sum,sum+l*m); printf("Case %d:\n",k++); scanf("%d",&t); while(t--) { scanf("%d",&z); for(j=0;j<n;j++) if(f(z-c[j],0,l*m)) break; if(j!=n) printf("YES\n"); else printf("NO\n"); } } return 0; }
HDU 2141 Can you find it? 二分查找
标签:
原文地址:http://www.cnblogs.com/Noevon/p/5327217.html