Topcoder Open Round 1 A Similars enumeration + pressure

Source: Internet
Author: User

Test instructions: Ask you between A-B to ask you to choose two numbers to make these two numbers the same number with the same number.

Solution Idea: Enumerate all the numbers between a-B, divide the number into 10 binary hash state compression, and then n^2 all the compressed values to find the maximum value.

Problem Solving Code:

1 //BEGIN CUT here2 /*3 4 */5 //END CUT here6 #line7 "Similars.cpp"7#include <cstdlib>8#include <cctype>9#include <cstring>Ten#include <cstdio> One#include <cmath> A#include <algorithm> -#include <vector> -#include <string> the#include <iostream> -#include <sstream> -#include <map> -#include <Set> +#include <queue> -#include <stack> +#include <fstream> A#include <numeric> at#include <iomanip> -#include <bitset> -#include <list> -#include <stdexcept> -#include <functional> -#include <utility> in#include <ctime> - using namespacestd; to  + #definePB push_back - #defineMP Make_pair the  * #defineREP (I,n) for (i=0;i< (n); ++i) $ #definefor (i,l,h) for (i= (l); i<= (h); ++i)Panax Notoginseng #defineFORD (i,h,l) for (i= (h); i>= (L); -  thetypedef vector<int>VI; +typedef vector<string>VS; Atypedef vector<Double>VD; thetypedefLong LongLL; +typedef pair<int,int>PII; -  $Map <ll,int>MP; $Map <ll,int>:: iterator ti,tj; - inths[ One]; -  the intpp (LL a,ll b) - {Wuyi    intAns =0 ;  the     while(A &&b) -    { Wu        if(a&b&1==1 ) -        { AboutAns + + ;  $        } -A = a >>1;  -b = b >>1;  -    } A    returnans; + } the voidChangeintL) - { $memset (HS,0,sizeof(HS)); the   intt =0 ;  the    while(L) the   { theHs[l%Ten] =1;  -L/=Ten ;  in   } theLL tmp =0 ;  the    for(inti =0; I <=9; i + +) About   { the      if(Hs[i]) theTMP + = (1<<i); the   } +   //printf ("%lld\n", TMP); -MP[TMP] + +; the }Bayi classSimilars the { the          Public: -         intMaxsim (intLintR) -         { the mp.clear (); the             intAns =0 ; the               for(inti = L; I <= R; i + +) the              { - Change (i); the              } the               for(Ti = Mp.begin (); Ti! = Mp.end (); ti++) the                   for(TJ = ti; TJ! = Mp.end (); tj++)94                  { the                      if(Ti = =TJ) the                      { the                         if(Ti->second >=2)98                         { Aboutans = max (ans,pp (ti->first,tj->First )); -                         }101}Else{102ans = max (ans,pp (ti->first,tj->First ));103                      }104                  } the              returnans;106         }107         108 //BEGIN CUT here109      Public: the     voidRun_test (intcase) {if(Case = =-1) || (Case = =0)) Test_case_0 ();if(Case = =-1) || (Case = =1)) Test_case_1 ();if(Case = =-1) || (Case = =2)) test_case_2 ();if(Case = =-1) || (Case = =3)) Test_case_3 ();if(Case = =-1) || (Case = =4) ) test_case_4 (); }111     Private: theTemplate <typename t>stringPrint_array (ConstVector<t> &v) {ostringstream os; OS <<"{ "; for(TypeName Vector<t>::const_iterator iter = V.begin (); ITER! = V.end (); ++iter) OS <<'\"'<< *iter <<"\","; OS <<" }";returnos.str ();}113     voidVerify_case (intCase,Const int&expected,Const int&received) {Cerr <<"Test Case #"<< Case <<"...";if(expected = = Received) Cerr <<"PASSED"<< Endl;Else{Cerr <<"FAILED"<< Endl; Cerr <<"\texpected: \ ""<< expected <<'\"'<< Endl; Cerr <<"\treceived: \ ""<< Received <<'\"'<<Endl;} } the     voidTest_case_0 () {intARG0 =1;intARG1 =Ten;intARG2 =1; Verify_case (0, Arg2, Maxsim (Arg0, Arg1)); } the     voidTest_case_1 () {intARG0 =1;intARG1 = About;intARG2 =2; Verify_case (1, Arg2, Maxsim (Arg0, Arg1)); } the     voidTest_case_2 () {intARG0 = About;intARG1 = -;intARG2 =0; Verify_case (2, Arg2, Maxsim (Arg0, Arg1)); }117     voidTest_case_3 () {intARG0 = +;intARG1 =1010;intARG2 =2; Verify_case (3, Arg2, Maxsim (Arg0, Arg1)); }118     voidTest_case_4 () {intARG0 =444;intARG1 =454;intARG2 =2; Verify_case (4, Arg2, Maxsim (Arg0, Arg1)); }119  - //END CUT here121 122 };123 124 //BEGIN CUT here the intMain ()126 {127 similars ___test; -___test.run_test (-1);129         return 0; the }131 //END CUT here
View Code

Topcoder Open Round 1 A Similars enumeration + pressure

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.