Hdu 4528 Xiao Ming series Story--Hide and seek

Source: Internet
Author: User
Tags ming

At first, I was wondering why I was wrong, and then I learned that the problem was that we could go back. Open 4-D visit Array record State, the state is different then go backward, the same and then go backwards.

1
30 31 95
S ..... ..................
.. X............................
... X...........................
.... X..........................
..... X.........................
...... X........................
....... X.......................
........ X......................
......... X.....................
.......... X....................
........... X...................
............ X..................
............. X.................
.............. X................
............... X...............
................ X..............
................. X.............
.................. X............
................... X...........
.................... X..........
..................... X.........
...................... X........
....................... X.......
........................ X......
......................... X.....
.......................... X....
........................... X...
............................ X..
............................. XE
.............................. D

The result is 88, if this set of data can be over then there is no problem.

#include <iostream> #include <queue> #include <cstring>using namespace Std;int N,m,t;char mapp[105][ 105];int visit[105][105][2][2];int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};int dx,dy,ex,ey,sx,sy;int re;int Flag1,    flag2;struct stu{int x,y,s; int flag1,flag2;};    int judgee (int x,int y) {int flag=0;        if (x==ex) {int nn=min (Y,ey), Mm=max (Y,ey);        int sum=0;        for (int i=nn+1;i<mm;i++) {if (mapp[x][i]== '. ') sum++;    } if (sum== (mm-nn-1)) flag=1;        } if (y==ey) {int nn=min (X,EX), Mm=max (X,EX);        int sum=0;        for (int i=nn+1;i<mm;i++) {if (mapp[i][y]== '. ') sum++;    } if (sum== (mm-nn-1)) flag=1; } return flag;    int judged (int x,int y) {int flag=0;        if (X==DX) {int nn=min (y,dy), Mm=max (Y,dy);        int sum=0;        for (int i=nn+1;i<mm;i++) {if (mapp[x][i]== '. ') sum++;    } if (sum== (mm-nn-1)) flag=1;  } if (Y==dy)  {int nn=min (X,DX), Mm=max (X,DX);        int sum=0;        for (int i=nn+1;i<mm;i++) {if (mapp[i][y]== '. ') sum++;    } if (sum== (mm-nn-1)) flag=1; } return flag;    void BFs () {stu x, y;    queue<stu>root;    x.x=sx;x.y=sy;x.s=0;x.flag1=0;x.flag2=0;    Root.push (x);    if (Judgee (x.x,x.y)) x.flag1=1;    if (judged (x.x,x.y)) x.flag2=1;    Visit[x.x][x.y][x.flag1][x.flag2]=1;        while (Root.size ()) {X=root.front ();        cout<<x.x<<x.y<<endl;        if (Judgee (x.x,x.y)) x.flag1=1;        if (judged (x.x,x.y)) x.flag2=1;         cout<<x.x<<x.y<<x.flag1<<x.flag2<<endl;        if (x.flag1&&x.flag2) {Re=x.s;return;}        Root.pop ();            for (int i=0;i<4;i++) {y.x=x.x+dir[i][0];            Y.Y=X.Y+DIR[I][1];            Y.FLAG1=X.FLAG1;            Y.flag2=x.flag2;            y.s=x.s+1; if (y.x<0| | y.x>=n| | y.y<0| | y.y>=m| | VISIT[Y.X][Y.Y][Y.FLAG1] [y.flag2]| | mapp[y.x][y.y]!= '. ' | |            Y.s>t) {continue;}            Root.push (y);        Visit[y.x][y.y][y.flag1][y.flag2]=1;    }}}int Main () {int u,p;    cin>>u;        for (int p=0;p<u;p++) {cin>>n>>m>>t;                for (int i=0;i<n;i++) {for (int j=0;j<m;j++) {cin>>mapp[i][j];                if (mapp[i][j]== ' S ') sx=i,sy=j;                if (mapp[i][j]== ' E ') ex=i,ey=j;               if (mapp[i][j]== ' D ') dx=i,dy=j;            Visit[i][j]=-1;        }} memset (Visit,0,sizeof (visit));        Mapp[sx][sy]= '. ';        Re=-1;        BFS ();        cout<< "Case" <<p+1<< ":" <<endl;    cout<<re<<endl; } return 0;}


Hdu 4528 Xiao Ming series Story--Hide and seek

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.