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.
InputThere 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. OutputFor 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 Input3 3 31 2 31 2 31 2 331410
Sample Output
Case 1:NOYESNO 给三组整数,在下面每给一个整数,判断从三组数各取一个相加与此整数是否可以相等。 直接暴力复杂度为O(N^3),不可行。可以将前两组枚举,复杂度为O(N^2),再排序,对于每一个目标数,枚举第三组数,二分查找前两组的和即可。 源代码: #include#include #include using namespace std; int a[505],b[505],c[505],d[250005]; int main() { int L,M,N,S,s=1,x,y,z,flag; while(cin>>L>>M>>N) { y=0; flag=0; cout<<"Case "< <<":"<>a[i]; for(int i=0;i >b[i]; for(int i=0;i >c[i]; for(int j=0;j >S; for(int i=0;i >x; flag=0; for(int j=0;j