HDU 1728 BFS

Source: Internet
Author: User



# Include <iostream> # include <cstring> # include <string> # include <cstdio> # include <cmath> # include <algorithm> # include <vector> # include <queue> # include <map> # define INF 0x3f3f3f # define ll _ int64 # define mod 1000000007 using namespace STD; struct node {int X, Y, CNT;} Now, TMP; int DX [] = {1,-1, 0}; int dy [] = {0, 0, -110}; char MP [110] [110]; int vis [110] [], K, x1, x2, YY1, Y2, n, m; int OK (INT X, int y) {If (x> = 0 & x <n & Y> = 0 & Y <M & MP [x] [Y]! = '*') Return 1; return 0;} int BFS () {queue <node> q; now. X = x1; now. y = YY1; q. push (now); While (! Q. empty () {now = Q. front (); q. pop (); For (INT I = 0; I <4; I ++) {TMP. X = now. X + dx [I]; TMP. y = now. Y + dy [I]; while (OK (TMP. x, TMP. y) // make sure that the number of turns at the specified position is the least when the same direction is low. {If (vis [TMP. x] [TMP. y] =-1) {vis [TMP. x] [TMP. y] = vis [now. x] [now. y] + 1; if (TMP. X = X2 & TMP. y = Y2 & Vis [TMP. x] [TMP. y] <= k) return 1; q. push (TMP);} TMP. X = TMP. X + dx [I]; TMP. y = TMP. Y + dy [I] ;}}return 0 ;}int main () {int t; scanf ("% d", & T); While (t --) {scanf ("% d", & N, & M); For (INT I = 0; I <n; I ++) scanf ("% s ", MP [I]); scanf ("% d", & K, & YY1, & X1, & Y2, & x2); X1 --; x2 --; YY1 --; Y2 --; memset (VIS,-1, sizeof vis); If (BFS () printf ("Yes \ n "); else printf ("NO \ n");} return 0 ;}


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.