"Hdoj" 3325 Arithmetically challenged

Source: Internet
Author: User

Simple DFS.

1 /*3325*/2#include <iostream>3#include <Set>4#include <cstdio>5#include <cstring>6#include <algorithm>7 using namespacestd;8 9 #defineMAXN 100005Ten #defineINF 0x3f3f3f3f One  A intBUF[MAXN]; - inta[4]; - Set<int>S; the Set<int>:: iterator iter; -  - intCalintAintBintop) { -     if(OP = =0)returnA +b; +     if(OP = =1)returnA-b; -     if(OP = =2)returnA *b; +     if(OP = =3)return(b==0|| A%B)? inf:a/b; A     returnINF; at } -  - voidf () { -     intI, J, K; -     inttmp1, TMP2; -     intans; in      -     //( (AB) C) D (AB) (CD) to      for(i=0; i<4; ++i) { +Tmp1 = Cal (a[0], a[1], i); -         if(TMP1 = =INF) the             Continue; *          for(j=0; j<4; ++j) { $TMP2 = Cal (TMP1, a[2], j);Panax Notoginseng             if(TMP2! =INF) { -                  for(k=0; k<4; ++k) { theans = cal (TMP2, a[3], k); +                     if(ans! =INF) A S.insert (ans); the                 } +             } -TMP2 = Cal (a[2], a[3], j); $             if(TMP2! =INF) { $                  for(k=0; k<4; ++k) { -Ans =cal (Tmp1, TMP2, k); -                     if(ans! =INF) the S.insert (ans); -                 }Wuyi             } the         } -     } Wu      -     //(A (BC)) d A ((BC) d) About      for(i=0; i<4; ++i) { $Tmp1 = Cal (a[1], a[2], i); -         if(TMP1 = =INF) -             Continue; -          for(j=0; j<4; ++j) { ATMP2 = Cal (a[0], TMP1, j); +             if(TMP2! =INF) { the                  for(k=0; k<4; ++k) { -ans = cal (TMP2, a[3], k); $                     if(ans! =INF) the S.insert (ans); the                 } the             } theTMP2 = Cal (TMP1, a[3], j); -             if(TMP2! =INF) { in                  for(k=0; k<4; ++k) { theans = cal (a[0], TMP2, k); the                     if(ans! =INF) About S.insert (ans); the                 } the             } the         } +     } -      the     //A (B (CD))Bayi      for(i=0; i<4; ++i) { theTmp1 = Cal (a[2], a[3], i); the         if(TMP1 = =INF) -             Continue; -          for(j=0; j<4; ++j) { theTMP2 = Cal (a[1], TMP1, j); the             if(TMP2! =INF) { the                  for(k=0; k<4; ++k) { theans = cal (a[0], TMP2, k); -                     if(ans! =INF) the S.insert (ans); the                 } the             }94         } the     } the } the 98 intMain () { About     intt =0, N; -     intI, J, K;101     intans;102     103 #ifndef Online_judge104Freopen ("data.in","R", stdin); theFreopen ("Data.out","W", stdout);106     #endif107     108      while(SCANF ("%d%d%d%d", &a[0],&a[1],&a[2],&a[3])!=eof && (a[0]+a[1]+a[2]+a[3])) {109 s.clear (); theSort (A, A +4);111          Do { the f ();113} while(Next_permutation (A, A +4)); then =0; the          for(Iter=s.begin (); Iter!=s.end (); + +iter) thebuf[n++] = *iter;117Ans = k =0;118          for(i=1; i<n; ++i) {119             if(buf[i]==buf[i-1]+1) -++K;121             Else122K =0;123             if(Ans <=k) {124Ans =K; thej =Buf[i];126             }127         } -printf"Case %d:%d to%d\n", ++t, J-ans, j);129     } the     131     return 0; the}

"Hdoj" 3325 Arithmetically challenged

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.