Can you find it?
Time Limit : 10000/3000ms (Java/Other) Memory Limit : 32768/10000K (Java/Other)
Total Submission(s) : 25 Accepted Submission(s) : 7
Problem Description
Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate if you can find the three numbers Ai, Bj, Ck, which satisfy the formula Ai+Bj+Ck = X.
Input
There are many cases. Every data case is described as followed: In the first line there are three integers L, N, M, in the second line there are L integers represent the sequence A, in the third line there are N integers represent the sequences B, in the forth line there are M integers represent the sequence C. In the fifth line there is an integer S represents there are S integers X to be calculated. 1<=L, N, M<=500, 1<=S<=1000. all the integers are 32-integers.
Output
For each case, firstly you have to print the case number as the form "Case d:", then for the S queries, you calculate if the formula can be satisfied or not. If satisfied, you print "YES", otherwise print "NO".
Sample Input
3 3 3 1 2 3 1 2 3 1 2 3 3 1 4 10
Sample Output
Case 1: NO YES NO
题意:分别有a,b,c三个数组,给出一个数,看这个数能不能再a,b,c,里面分别找出一个数求和得到
题解:先把两个数组加起来,另外一个数组用二分;
代码:
1 #include2 #include 3 #include 4 using namespace std; 5 __int64 D[1000010],A[510],B[510],C[510],L,N,M;//D数组要开大;;; 6 int erfen(__int64 *a,__int64 c,__int64 d){ 7 int l,r,mid; 8 l=0;r=L*N-1;//// 9 while(l<=r){10 mid=(l+r)/2;11 if(a[mid]+c
stl:
1 #include2 #include 3 #include 4 using namespace std; 5 __int64 D[1000010],A[510],B[510],C[510],L,N,M;//D数组要开大;;; 6 /*int erfen(__int64 *a,__int64 c,__int64 d){ 7 int l,r,mid; 8 l=0;r=L*N-1; 9 while(l<=r){10 mid=(l+r)/2;11 if(a[mid]+c
map和set做全都MLE了,无奈了,别人的都对的;
set代码:
1 #include2 #include 3 using namespace std; 4 const int MAXN=505; 5 int A[MAXN],B[MAXN],C[MAXN]; 6 int main(){ 7 int L,N,M,S,X,flot=0,ok; 8 while(~scanf("%d%d%d",&L,&N,&M)){ set num; 9 for(int i=0;i
map代码:
1 #include2 #include