BFS POJ 3414 Pots

Source: Internet
Author: User

Topic Portal

1 /*2 BFS: Six kinds of situations to discuss, BFS easy to solve3 at first I saw someone using DFS, I wrote it again, TLE. Or use BFS, the result of a special sentence error, a long time to amuse4 look at other people's code is simply suffering, fortunately I finally found their own code of Small error:)5 */6 /************************************************7 Author:running_time8 Created time:2015-8-3 14:17:249 File Name:P oj_3414_bfs.cppTen **************************************************/ One  A#include <cstdio> -#include <algorithm> -#include <iostream> the#include <sstream> -#include <cstring> -#include <cmath> -#include <string> +#include <vector> -#include <queue> +#include <deque> A#include <stack> at#include <list> -#include <map> -#include <Set> -#include <bitset> -#include <cstdlib> -#include <ctime> in using namespacestd; -  to #defineLson L, Mid, RT << 1 + #defineRson mid + 1, R, RT << 1 | 1 -typedefLong Longll; the Const intMAXN = 1e4 +Ten; * Const intINF =0x3f3f3f3f; $ Const intMOD = 1e9 +7;Panax Notoginseng structPoint { -     intA, B, step; the     intOP[MAXN]; + }; A BOOLvis[ the][ the]; the intA, B, C; + intans; -  $ voidBFS (void)  { $memset (Vis,false,sizeof(Vis)); -Queue<point> Q; Q.push (point) {0,0,0}); -      while(!Q.empty ()) { thePoint P =Q.front (); Q.pop (); -         if(P.a = = C | | p.b = =C) {Wuyiprintf ("%d\n", p.step); the              for(intI=1; i<=p.step; ++i) { -                 if(P.op[i] = =1) puts ("FILL (1)"); Wu                 Else if(P.op[i] = =2) puts ("FILL (2)"); -                 Else if(P.op[i] = =3) puts ("DROP (1)"); About                 Else if(P.op[i] = =4) puts ("DROP (2)"); $                 Else if(P.op[i] = =5) puts ("pour (ON)"); -                 Else if(P.op[i] = =6) puts ("pour (2,1)"); -             } -             return ; A         } + Point tmp; the         if(P.a < a &&!)vis[a][p.b]) { -VIS[A][P.B] =true; $TMP = P;  Tmp.a = A; Tmp.op[++tmp.step] =1;//FILL1 the Q.push (TMP); the         } the         if(P.b < b &&!)Vis[p.a][b]) { theVIS[P.A][B] =true; -TMP = P;  TMP.B = b; Tmp.op[++tmp.step] =2;//FILL2 in Q.push (TMP); the         } the         if(P.a >0&&!vis[0][p.b]) { Aboutvis[0][P.B] =true; theTMP = P; Tmp.a =0; Tmp.op[++tmp.step] =3;//DROP1 the Q.push (TMP); the         } +         if(P.b >0&&!vis[p.a][0])    { -vis[p.a][0] =true; theTMP = P; TMP.B =0; Tmp.op[++tmp.step] =4;//DROP2Bayi Q.push (TMP); the         } the         if(P.a >0&& P.B <B) { -             intt = min (p.a, B-p.b); -             if(!vis[p.a-t][p.b+T]) { theVIS[P.A-T][P.B+T] =true;//pour1->2 theTMP = P; Tmp.a-= t; Tmp.b + = t; Tmp.op[++tmp.step] =5; the Q.push (TMP); the             } -         } the         if(P.b >0&& P.a <A) { the             intt = min (p.b, A-p.a); the             if(!vis[p.a+t][p.b-T]) {94VIS[P.A+T][P.B-T] =true;//pour2->1 theTMP = P; Tmp.a + = t; TMP.B-= t; Tmp.op[++tmp.step] =6; the Q.push (TMP); the             }98         } About     } - 101Puts ("Impossible");102 }103 104 intMainvoid)    {//POJ 3414 Pots the      while(SCANF ("%d%d%d", &a, &b, &c) = =3) {106 BFS ();107     }108 109     return 0; the}

BFS POJ 3414 Pots

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.