Dfs:red and Black (POJ 1979)

Source: Internet
Author: User

               

Red and Black

The main idea: a person in a rectangular house, you can walk the black area, can not walk the red area, from a certain point, he can go to the maximum number of rooms?

Not much to say, Dfs deep search can, water problem

Just be careful not to mistake the rows and columns. I just missed it once. haha

   

1#include <stdio.h>2#include <stdlib.h>3 #defineMax_n 204 5 Static intDp[max_n][max_n];6 Static intStartX;7 Static intStarty;8 Static intans;9 Ten voidDfs_search (Const int,Const int,Const int,Const int); One  A intMainvoid) - { -     intW, H, I, J; the      while(~SCANF ("%d%d", &w, &H)) -     { -         if(W = =0&& H = =0) -              Break; +Ans =0;//Start at the beginning. -          for(i =0; i < H; i++)//Read Map +         { A GetChar (); at              for(j =0; J < W; J + +) -             { -scanf"%c", &dp[i][j]); -                 if(Dp[i][j] = ='@'){ -StartX = i; Starty =J; -                 } in             } -         } to Dfs_search (StartX, Starty, W, H); +printf"%d\n", ans); -     } the  *     return 0; $ }Panax Notoginseng  - voidDfs_search (Const intXConst intYConst intWConst intH) the { +Dp[x][y] ='#'; Aans++; the     if(X-1>=0&& Dp[x-1][y]! ='#') +Dfs_search (X-1, Y, W, H); -     if(x +1< H && Dp[x +1][y]! ='#') $Dfs_search (x +1, Y, W, H); $     if(Y-1>=0&& Dp[x][y-1] !='#') -Dfs_search (x, Y-1, W, H); -     if(Y +1< W && Dp[x][y +1] !='#') theDfs_search (x, y +1, W, H); -}

Dfs:red and Black (POJ 1979)

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.