Maze Treasure Hunt (i)----State compression

Source: Internet
Author: User

Basic State Compressionwrite down the current changes, the next time the appropriate use of the results of the last search is attached below the slag code
1#include <stdio.h>2#include <string.h>3#include <math.h>4#include <iostream>5#include <algorithm>6#include <queue>7#include <vector>8#include <Set>9#include <stack>Ten#include <string> One#include <sstream> A#include <map> -#include <cctype> - using namespacestd; the intc[7],n,m,b[4][2]={0,-1,0,1,-1,0,1,0},visited[ A][ A],flag; - Chara[ A][ A]; - structnode - { +     intx, y; - }; +Queue<node>Q; A BOOLCheckintXinty) at { -     if(a[y][x]>='A'&&a[y][x]<='E')//if it's a door and -     { -         if(c[a[y][x]-'A']!=0)//a plan to not have enough keys -             return false; -     } in     return true; - } to voidBFS (intXintYint&Mark) + { -Node q={x, y}; the Q.push (Q); *      while(!q.empty ()) $     {Panax NotoginsengNode e=Q.front (); - Q.pop (); the          for(intI=0;i<4; i++) +         { Aq.x=e.x+b[i][0],q.y=e.y+b[i][1]; the             if(a[q.y][q.x]!='X'&&q.x>=0&&q.x<m&&q.y>=0&&q.y<n&&!visited[q.y][q.x]&&Check (Q.X,Q.Y)) +             { -visited[q.y][q.x]=1; $ Q.push (Q); $                 if(a[q.y][q.x]>='a'&&a[q.y][q.x]<='e') -                 { -c[a[q.y][q.x]-'a']--; the                     if(c[a[q.y][q.x]-'a']==0) -mark++;Wuyia[q.y][q.x]='.'; the                 } -                 if(a[q.y][q.x]=='G') Wuflag=1; -             } About         } $     } - } - intMain () - { A     intSx,sy; +      while(SCANF ("%d%d", &n,&m), (n| |m)) the     { -Memset (c,0,sizeof(c)); $          for(intI=0; i<n;i++) the         { the              for(intj=0; j<m;j++) the             { thescanf"%c",&a[i][j]); -                 if(a[i][j]=='a') inc[0]++; the                 if(a[i][j]=='b') thec[1]++; About                 if(a[i][j]=='C') thec[2]++; the                 if(a[i][j]=='D') thec[3]++; +                 if(a[i][j]=='e') -c[4]++; the                 if(a[i][j]=='S')Bayi                 { thesx=J; thesy=i; -                 } -             } the         } theMemset (visited,0,sizeof(visited)); thevisited[sy][sx]=1; the         intmark=1; -flag=0; the          while(mark--) the         { the              while(!q.empty ())94 Q.pop (); the BFS (Sx,sy,mark); theMemset (visited,0,sizeof(visited)); the             if(flag)98                  Break; About         } -         if(flag)101printf"yes\n");102         Else103printf"no\n");104     } the     return 0;106}

Maze Treasure Hunt (i)----State compression

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.