HDU 2141:can you find it? (two points)

Source: Internet
Author: User

Select a number in each of the three arrays to determine whether the addition can get the target number. At first, I wanted to find impossible~ violent.

Contact two points, after the senior guidance to merge the first two arrays, the first two arrays all possible and save in the new array, and then according to the third array, two points to find a new array to determine whether the number of required

#include"Cstdio"#include"CString"#include"algorithm"#defineMAXN 505using namespacestd;intsum[maxn*MAXN];intTail=0, p=1;BOOLJudgeintBinttarget) {   intlow=0, high=tail-1;  while(low<=High ) {   intMid= (Low+high)/2; if(Sum[mid]+b==target)return true; Else if(Sum[mid]+b<target) low=mid+1; Elsehigh=mid-1; }    return false;}intMain () {intLen1,len2,len3;  while(SCANF ("%d%d%d", &AMP;LEN1,&AMP;LEN2,&AMP;LEN3)! =EOF) {   intNUM1[MAXN],NUM2[MAXN],NUM3[MAXN];  for(intI=0; i<len1;i++) scanf ("%d",&Num1[i]);  for(intI=0; i<len2;i++) scanf ("%d",&Num2[i]);  for(intI=0; i<len3;i++) scanf ("%d",&Num3[i]); Sort (num3,num3+Len3); Tail=0; memset (SUM,0,sizeof(sum));  for(intI=0; i<len1;i++)             for(intj=0; j<len2;j++) Sum[tail++]=num1[i]+Num2[j]; Sort (Sum,sum+tail); intN; scanf ("%d",&N); printf ("Case %d:\n", p++);  while(n--)        {   intTemp,i=0, ok=0; scanf ("%d",&temp);  while(!ok&&i<Len3)if(Judge (num3[i++],temp)) ok=1; if(OK) printf ("yes\n"); Elseprintf"no\n"); }    }    return 0;}
View Code

HDU 2141:can you find it? (two points)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.