Hdu 21,412 min

Source: Internet
Author: User

Test instructions is for you. Three arrays have n m k number from three arrays each take a number can be equal to s

At first I didn't notice that the number could be negative WA many times


Don't think direct violence definitely timed out

Now combines two numbers with a small number of binary enumerators (very time-saving) with fewer violent enumerators


#include <stdio.h> #include <string.h> #include <iostream>using namespaceStd; int Main () {  int Num1[510],Num2[510],Num3[510]; int Mark[300000]; int I,J,K,P,D=1; int N,M;  while (~scanf("%d%d%d",&N,&M,&K)  {  for( I=1;I<=N;I++)scanf("%d",&Num1[I]);  for (I=1;I<=M;I++)scanf("%d",&Num2[I]);P=0;  for (I=1;I<=N;I++)  for (J=1;J<=M;J++)Mark[++P]=Num1[I]+Num2[J];Sort(Mark+1,Mark+1+P);  for (I=1;I<=K;I++)scanf("%d",&Num3[I]);Sort(Num3+1,Num3+1+K); int S;scanf("%d",&S);Printf("Case%d:\n",D++);  while (S --) {  int Sum;scanf("%d",&Sum); int Flash=0; int Left,Right,Mid;  for (I=1;I<=K;I++) {Left=1;Right=P;  while (Left<=Right) {Mid=(Left+Right)/2; if (Mark[Mid]>Sum-Num3[I])Right=Mid-1; else if (Mark[Mid]<Sum-Num3[I])Left=Mid+1; Else  {Flash=1;  Break ; }}  if( Flash )  break; }  if( Flash)Printf("yes\n"); Else Printf("no\n"); }}  return 0;}

Hdu 21,412 min

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.