Skip to content

Instantly share code, notes, and snippets.

@lackofdream
Created April 17, 2015 10:21
Show Gist options
  • Save lackofdream/1d5637ce39ad8eea572a to your computer and use it in GitHub Desktop.
Save lackofdream/1d5637ce39ad8eea572a to your computer and use it in GitHub Desktop.
HDU2141
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <vector>
#include <fstream>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#define MAX(a,b) (a>b?a:b)
#define sd(x) scanf("%d",&x)
#define sdd(a,b) scanf("%d%d",&a,&b)
#define sddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define slflf(x,y) scanf("%lf%lf",&x,&y)
#define abs(x) (x<0?(-x):x)
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
using namespace std;
int A[505],B[505],C[505];
long long ASUMB[250500];
bool BinSearch(int l,int r,long long q)
{
int m ;
while(l<=r)
{
m = (l+r)/2;
if (ASUMB[m]==q)
{
printf("YES\n");
return true;
}
else if (ASUMB[m]<q)
{
l = m+1;
}
else r = m - 1;
}
return false;
}
int main()
{
int l,n,m,tcase=0;
while(~sddd(l,n,m))
{
printf("Case %d:\n",++tcase);
int cur=0;
for (int i=0; i<l; i++) sd(A[i]);
for (int i=0; i<n; i++) sd(B[i]);
for (int i=0; i<m; i++) sd(C[i]);
for (int i=0; i<l; i++)
for (int j=0; j<n; j++)
ASUMB[cur++]=A[i]+B[j];
sort(ASUMB,ASUMB+cur);
int t,q;
sd(t);
while(t--)
{
sd(q);
bool flag=false;
for (int i=0; i<m; i++)
{
long long v = q - C[i];
if (BinSearch(0,cur,v))
{
flag=true;
break;
}
}
if (!flag) printf("NO\n");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment