﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-comiz-最新评论</title><link>http://www.cppblog.com/comiz/CommentsRSS.aspx</link><description /><language>zh-cn</language><pubDate>Sun, 04 Nov 2007 11:34:41 GMT</pubDate><lastBuildDate>Sun, 04 Nov 2007 11:34:41 GMT</lastBuildDate><generator>cnblogs</generator><item><title>re: a problem of maze</title><link>http://www.cppblog.com/comiz/archive/2007/11/04/35861.html#35862</link><dc:creator>comiz</dc:creator><author>comiz</author><pubDate>Sun, 04 Nov 2007 11:35:00 GMT</pubDate><guid>http://www.cppblog.com/comiz/archive/2007/11/04/35861.html#35862</guid><description><![CDATA[using System;<br>using System.Collections;<br>using System.ComponentModel;<br>using System.Data;<br>using System.Threading;<br><br>namespace TroytownKeeper<br>{<br><br> public class TroytownKeeper<br> {<br>  string [] maze;<br>  bool [,]used=new bool[100,100];<br>  int sum=0;<br>  public TroytownKeeper()<br>  {<br><br> <br><br>  }<br><br>  public int LimeLiters(string [] maze)<br>  {<br>   this.maze=maze;<br>   for(int x=0;x&lt;maze.GetLength(0);x++)<br>   {<br>    if(maze[x][0]=='.') dfs(x,0);<br>    if(maze[x][maze[0].Length-1]=='.') dfs(x,maze[0].Length-1);<br>   }<br>   for(int y=0;y&lt;maze[0].Length-1;y++)<br>   {<br>    if(maze[0][y]=='.') dfs(0,y);<br>    if(maze[maze.GetLength(0)-1][y]=='.') dfs(maze.GetLength(0)-1,y);<br>   }<br><br>   for(int x=0;x&lt;maze.GetLength(0);x++)<br>    for(int y=0;y&lt;maze[0].Length;y++)<br>     if(maze[x][y]=='#')<br>     {<br>      //upside<br>      if(x==0)<br>       sum++;<br>      if(x&lt;maze.Length-1&amp;&amp;used[x+1,y])<br>       sum++;<br>      //leftside<br>      if(y==0)<br>       sum++;<br>      if(y&gt;0&amp;&amp;used[x,y-1])<br>       sum++;<br>      //underside<br>      if(x==maze.Length-1)<br>       sum++;<br>      if(x&gt;0&amp;&amp;used[x-1,y])<br>       sum++;<br>      //rightside<br>      if(y==maze[0].Length-1)<br>       sum++;<br>      if(y&lt;maze[0].Length-1&amp;&amp;used[x,y+1])<br>       sum++;<br>     }<br>   return sum;<br>  }<br><br>  static void Main(string[] args)<br>  {<br>   TroytownKeeper TK=new TroytownKeeper();<br>   string [] str={&quot;##..#&quot;<br>        ,&quot;#.#.#&quot;<br>        ,&quot;#.#.#&quot;<br>        ,&quot;#####&quot;};<br>   int count=TK.LimeLiters(str);<br>   Console.WriteLine(count.ToString());<br>  }<br><br><br>  void dfs(int x,int y)<br>  {<br>   used[x,y]=true;<br>   if(x&lt;maze.GetLength(0)&amp;&amp;maze[x+1][y]=='.'&amp;&amp;!used[x+1,y]) dfs(x+1,y);<br>   if(y&lt;maze[0].Length&amp;&amp;maze[x][y+1]=='.'&amp;&amp;!used[x,y+1]) dfs(x,y+1);<br>   if(x&gt;0&amp;&amp;maze[x-1][y]=='.'&amp;&amp;!used[x-1,y]) dfs(x-1,y);<br>   if(y&gt;0&amp;&amp;maze[x][y-1]=='.'&amp;&amp;!used[x,y-1]) dfs(x,y-1);<br>  }<br> }<br>}<br><br><img src ="http://www.cppblog.com/comiz/aggbug/35862.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/comiz/" target="_blank">comiz</a> 2007-11-04 19:35 <a href="http://www.cppblog.com/comiz/archive/2007/11/04/35861.html#35862#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>