题目链接:
【题目大意】:
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.
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
if(sort[mid]<ans) left=mid+1; else if(sort[mid]>ans) right=mid-1; else {flag=true;break;}
代码:
#includeusing namespace std;const int N=505;int A[N],B[N],C[N],D[N*N];bool get(int sort[],int k,int ans)//合并后的数组/数组元素个数/和减去第三个数组元素剩下的值{ bool flag=false; int left=0,right=k,mid; while(left<=right) { mid=(left+right)>>1; if(sort[mid] ans) right=mid-1; else {flag=true;break;} } return flag;}int main(){ //freopen("1.txt","r",stdin); int l,n,z,m,S,tot=1; bool ok; while(scanf("%d%d%d",&l,&n,&m)!=EOF) { for(int i=0;i