705-slash maze // search

Source: Internet
Author: User

I found the gap between myself and the world.

At the beginning, I thought about how to simulate this maze. I wanted to search for Daniel online if I had no idea. The result is to replace '\' and '/' with a square, which is the opposite of what I think. But I gave up thinking. Ah, next time I will never do that.

Back to the beginning, we used a 2*2 square to simulate the slash at the beginning, but it was very troublesome to judge the direction of recursion. A total of 8 directions need to be determined. So we used 3*3 to simulate this slash. In this way, you only need to write down the number of squares that have been traversed to get the answer.

Below isCode:

# Include <stdio. h> # include <string. h> # define maxn 100 char map [maxn] [maxn]; int G [maxn * 3] [maxn * 3]; int vis [maxn * 3] [maxn * 3]; int W, H; int CNT; int tag; int sum; int move [4] [2] = {}, {-}, {}, {0,-1}; void DFS (int x, int y) {CNT ++; vis [x] [Y] = 1; int flag = 0; For (INT I = 0; I <4; I ++) {int dx = x + move [I] [0]; int DY = Y + move [I] [1]; if (dx> = 0 & DX <H * 3 & dy> = 0 & dy <w * 3) {If (G [dx] [dy] = 0 &&! Vis [dx] [dy]) DFS (dx, Dy) ;}} void color (int x, int y) // classify the cell in the boundary, the remain cells of all can be a loop {vis [x] [Y] = 1; for (INT I = 0; I <4; I ++) {int dx = x + move [I] [0]; int DY = Y + move [I] [1]; if (dx> = 0 & DX <H * 3 & dy> = 0 & dy <w * 3) {If (G [dx] [dy] = 0 &&! Vis [dx] [dy]) DFS (dx, Dy) ;}} int main () {int T = 0; while (scanf ("% d ", & W, & H) & W & H) {T ++; memset (G, 0, sizeof (g); memset (VIS, 0, sizeof (VIS); For (INT I = 0; I 

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.