Codeforces Round #301 (Div. 2) B. School Marks

Source: Internet
Author: User

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

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.