Uva 705 Slash Maze

Source: Internet
Author: User

The title means looking for the number of loops that can be formed in the graph, and the number of squares through which the maximum loop is passed.

The problem is not simply the square, but the oblique, so it is not easy. Later on the Internet to see other people's ideas, the figure magnified three times times, the enlightened.

Problem Solving report Link: http://blog.csdn.net/sio__five/article/details/18910097

I modified the code for a while, save myself to learn slowly later.

1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 intlength, width, grid, Max;7 intg[ -][ -], isvis[ -][ -];8 intmove[4][2] = {{0, -1},{0,1} , {-1,0} ,{1,0}};9 Ten BOOLIsIn (intXinty); One voidNoeffectfill (intXinty); A voidSetbound (); - voidDfs (intXinty); -  the intMain () - { - //freopen ("D:\\acm.txt", "R", stdin); -     intNo =1, Cyclenum; +      while(Cin>>length>>width, (length| |width)) { -width = width *3, length = length *3;//enlarge the graph three times times +Memset (G,0,sizeof(g)); Amemset (Isvis,0,sizeof(Isvis)); atMax =0; -Cyclenum =0; -          for(inti =1; I < width; i + =3){ -              for(intj =1; J < length; J + =3){ -                 Charch; -Cin>>ch; in                 if(ch = ='\\') -G[i-1][j-1] = G[i][j] = g[i +1][j +1] =1; to                 Else +G[i-1][j +1] = G[i][j] = g[i +1][j-1] =1; -             } the         } * Setbound (); $          for(inti =0; I < width; i++){Panax Notoginseng              for(intj =0; J < length; J + +){ -                 if(!g[i][j] &&!Isvis[i][j]) { theGrid =0; + Dfs (i, j); A                     if(Grid >= A) cyclenum++;//a small lattice larger than 12 is larger than 4, constituting a loop the                     if(Grid > Max) Max = grid;//record maximum number of squares +                 } -             } $         } $printf"Maze #%d:\n", no++); -         if(Cyclenum! =0) -printf"%d Cycles; the longest has length%d.\n", Cyclenum, Max/3); the         Else -printf"there is no cycles.\n");Wuyiprintf"\ n"); the     } -     return 0; Wu } - BOOLIsIn (intXinty) About { $     return(x >=0&& x < width && y >=0&& y <length); - } - voidNoeffectfill (intXinty) - { A     intNextx, Nexty, I; +Isvis[x][y] =1, g[x][y] =2; the      for(i =0; I <4; i++) {//fill out the outer space -NEXTX = x + move[i][0]; $Nexty = y + move[i][1]; the         if(IsIn (NEXTX, nexty) &&!isvis[nextx][nexty] &&!G[nextx][nexty]) the Noeffectfill (NEXTX, nexty); the     } the } - voidSetbound () in { the      for(inti =0; I < width; i++){ the         if(!g[i][0] &&!isvis[i][0])  AboutNoeffectfill (I,0);//set the perimeter boundary of a diagram the         if(!g[i][length-1] &&!isvis[i][length-1])  theNoeffectfill (i, Length-1); the     } +      for(intj =0; J < length; J + +){ -         if(!g[0][J] &&!isvis[0][j]) theNoeffectfill (0, j);//set the perimeter boundary of a diagramBayi         if(!g[width-1][J] &&!isvis[width-1][j]) theNoeffectfill (Width-1, j); the     } - } - voidDfs (intXintY//recursive look -up lattice the { the     intnextx, nexty; theIsvis[x][y] =1; thegrid++; -      for(inti =0; I <4; i++){ theNEXTX = x + move[i][0]; theNexty = y + move[i][1]; the         if(IsIn (NEXTX, nexty) &&!isvis[nextx][nexty] &&!G[nextx][nexty])94 Dfs (NEXTX, nexty); the     } the}

Uva 705 Slash Maze

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.