"Daily training"ice Cave (codeforces Round 301 Div.2 C)

Source: Internet
Author: User

Test instructions and analysis (Codeforces 540C)

The pit is killing me .... I was confused with a classic BFS problem, which is simpler than that one.
That is probably the case, an ice tower, the first time a block will be broken, the second crushing will fall. And then find the feasible solution.
But the question ... It's the first floor of the ice tower.
In other words, it's just a slightly limited two-dimensional maze problem.
The following is a good idea, but this data needs to be considered:

1 2XX1 11 1

The answer to this data is no. The workaround is to consider this: two arrays to record access status: Vis array and block array.

Code
#include <queue> #include <set> #include <iostream> #include <cstring> #include <algorithm > #include <vector> #define MP make_pair#define PB push_back#define fi first#define se second#define ZERO (x) Memse T ((x), 0, sizeof (x)) #define ALL (x) (x). Begin (), (x). End () #define REP (I, A, b) for (int i = (a); I <= (b); ++i) #define PE     R (I, A, b) for (int i = (a); I >= (b); i.) #define QUICKIO Ios::sync_with_stdio (FALSE);                      Cin.tie (0); Cout.tie (0); using namespace Std;bool iscracked[505][505];bool vis[505][505];set<pair<int,int> > S;int bx,    by,ex,ey,n,m;const int Dx[]={0,1,0,-1};const int Dy[]={1,0,-1,0};bool bfs () {queue<pair<int,int> > Q;    Q.push (MP (Bx,by));    S.insert (MP (Bx,by));    Iscracked[bx][by]=true;    Auto End_pair=mp (Ex,ey);        while (!q.empty ()) {Auto Now=q.front (); Q.pop (); if (Now==end_pair && iscracked[now.fi][now.se] && vis[now.fi][now.se]) return true;        cout<< "NP:" <<now.fi<< "" <<now.se<<endl;        Iscracked[now.fi][now.se]=true;        Vis[now.fi][now.se]=true;            Rep (i,0,3) {int tx=now.fi+dx[i], ty=now.se+dy[i]; if (tx>=1 && tx<=n && ty>=1 && ty<=m && (!iscracked[tx][ty]| |            (Tx==ex&&ty==ey)))                {Auto Tstat=mp (tx,ty);                cout<< "Trying to Go" <<tx<< "" <<ty<< "<<iscracked[tx][ty]<<endl; if (S.find (Tstat) ==s.end () | | tstat==end_pair) {//cout<< "Success" <<en                    dl                    S.insert (Tstat);                Q.push (Tstat); }}}} return false;}    int main () {cin>>n>>m; ZERO (iscracked);    ZERO (VIS);         Rep (i,1,n) {string str; cin>>str; Rep (j,0,m-1) {iscracked[i][j+1]=vis[i][j+1]=str[j]== ' X ';    }} cin>>bx>>by>>ex>>ey;    Vis[bx][by]=false; if (Bx==ex && by==ey && n==1 && m==1) cout<<string (BFS ()? "    YES ":" NO ") <<endl; return 0;}

Daily training "ice Cave (codeforces Round 301 Div.2 C)

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.