In fact, is very water a BFS problem, last night when the game did not see test instructions, missed a condition.
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <cmath>5#include <algorithm>6#include <Set>7#include <map>8#include <queue>9#include <stack>Ten#include <string> One#include <vector> A #defineMaxn - #defineINF 1000000000 - using namespacestd; the intvist[510][510]; - Charstr[510][510]; - intdirx[]={-1,0,1,0}; - intdiry[]={0,1,0,-1}; + intM,n,stx,sty,edx,edy; - intJudgeintXinty) + { A if(x>=0&&x<n&&y>=0&&y<m) at return 1; - return 0; - } - intBFS () - { -queue<int>Q; instx--; -sty--;edx--;edy--; to intnum=stx*m+sty; + Q.push (num); - //vist[stx][sty]--This place, because the beginning and the end may be the same the while(!q.empty ()) * { $num=Q.front ();Panax Notoginseng //printf ("%d==\n", num); - Q.pop (); the intxx=num/m; + intyy=num%m; A the for(intI=0;i<4; i++) + { - intnewx=xx+Dirx[i]; $ intnewy=yy+Diry[i]; $ if(newx==edx&&newy==edy&&vist[newx][newy]==0) - return 1; - if(Judge (Newx,newy) &&vist[newx][newy]>0) the { -Q.push (newx*m+newy);Wuyivist[newx][newy]--; the } - } Wu } - //printf ("==\n"); About return 0; $ - } - intMain () - { Ascanf"%d%d",&n,&m); + for(intI=0; i<n;i++) thescanf"%s", Str[i]); -scanf"%d%d",&stx,&sty); $scanf"%d%d",&edx,&edy); the for(intI=0; i<n;i++) the { the for(intj=0; j<m;j++) the { - if(str[i][j]=='X') invist[i][j]=0; the Else thevist[i][j]=1; About } the } the if(BFS ()) theprintf"yes\n"); + Else -printf"no\n"); the return 0;Bayi}
Codeforces Round #301 (Div. 2) B. School Marks