Bzoj 1054 [HAOI2008] Mobile Toys

Source: Internet
Author: User

Direct violence wide search can be.

"The internet has great God said two-way wide search speed, but direct violence wide search can be over"

The state in the queue is stored in binary order.

I used a comparison of SB's wording, do not spray qaq

1#include <queue>2#include <cstdio>3 4 using namespacestd;5 6UnsignedintStart, End;7 BOOLm[4][4];8 9 Const intDx[] = {+0, +0, +1, -1};Ten Const intDy[] = {+1, -1, +0, +0}; One  A voidInit () - { -     Charmap[4][4]; theUnsignedintTemp; -      for(inti =0; I! =4;++i) -     { -scanf"%s", Map +i); +Temp =0; -          for(intj =0; J! =4;++j) +(Temp <<=1) + = Map[i][j]-'0'; AStart + = (Temp << (i <<2)); at     } -      for(inti =0; I! =4;++i) -     { -scanf"%s", Map +i); -Temp =0; -          for(intj =0; J! =4;++j) in(Temp <<=1) + = Map[i][j]-'0'; -End + = (Temp << (i <<2)); to     } + } -  the intdist[100050]; *  $ voidBFS ()Panax Notoginseng { -queue<unsignedint>Q; the Q.push (Start); +UnsignedintTop, Temp, Go; A     intx, y; theDist[start] =1; +      while(Q.size ()) -     { $Top =Q.front (); $ Q.pop (); -          for(inti =0; I! =4;++i) -              for(intj =0; J! =4;++j) theM[I][J] = (Top & (1<< (i *4+ (3-J ))); -          for(inti =0; I! =4;++i)Wuyi              for(intj =0; J! =4;++j) the                 if(M[i][j]) -                      for(intK =0; K! =4;++k) Wu                     { -x = i + dx[k], y = j +Dy[k]; About                         if(x >=0&& x <4&& y >=0&& y <4) $                             if(!M[x][y]) -                             { - swap (M[i][j], m[x][y]); -Go =0; A                                  for(inti =0; I! =4;++i) +                                 { theTemp =0; -                                      for(intj =0; J! =4;++j) $(Temp <<=1) +=M[i][j]; theGo + = (Temp << (i <<2)); the                                 } the                                 if(!Dist[go]) the                                 { -Dist[go] = Dist[top] +1; in Q.push (Go); the                                 } the swap (M[i][j], m[x][y]); About                             } the                     } the         if(Dist[end]) the              Break; +     } - } the Bayi intMain () the { the init (); - BFS (); -printf"%u", Dist[end]-1); the     return 0; the}
Bzoj 1054

Bzoj 1054 [HAOI2008] Mobile Toys

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.