﻿<?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++博客-slytherin-文章分类-VIJOS</title><link>http://www.cppblog.com/slytherin/category/20132.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 23 Oct 2012 14:07:35 GMT</lastBuildDate><pubDate>Tue, 23 Oct 2012 14:07:35 GMT</pubDate><ttl>60</ttl><item><title>[VIJOS] P1011 滑雪</title><link>http://www.cppblog.com/slytherin/articles/193735.html</link><dc:creator>slytherin</dc:creator><author>slytherin</author><pubDate>Tue, 23 Oct 2012 12:22:00 GMT</pubDate><guid>http://www.cppblog.com/slytherin/articles/193735.html</guid><wfw:comment>http://www.cppblog.com/slytherin/comments/193735.html</wfw:comment><comments>http://www.cppblog.com/slytherin/articles/193735.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/slytherin/comments/commentRss/193735.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/slytherin/services/trackbacks/193735.html</trackback:ping><description><![CDATA[<div><span style="font-size: 12px;">记忆化搜索<br /><br />#include &lt;stdio.h&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">int way[4][2]={{0,1},{0,-1},{1,0},{-1,0}};</span></div><div><span style="font-size: 12px;">int a[501][501];</span></div><div><span style="font-size: 12px;">int f[501][501];</span></div><div><span style="font-size: 12px;">int v[501][501];</span></div><div><span style="font-size: 12px;">int r,c,fst;</span></div><div><span style="font-size: 12px;">long ans;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">void</span></div><div><span style="font-size: 12px;">init()</span></div><div><span style="font-size: 12px;">{</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp;freopen("hx.in","r",stdin);</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; scanf("%d%d",&amp;r,&amp;c);</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; int i,j;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; for(i=1;i&lt;=r;i++)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(j=1;j&lt;=c;j++)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;f[i][j]=1;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;scanf("%d",&amp;a[i][j]);</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;">}</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">void</span></div><div><span style="font-size: 12px;">dfs(int x,int y)</span></div><div><span style="font-size: 12px;">{</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; int i;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; for(i=0;i&lt;=3;i++)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; if( a[x+way[i][0]][y+way[i][1]] &lt; a[x][y])</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(!v[x+way[i][0]][y+way[i][1]])</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v[x+way[i][0]][y+way[i][1]]=1;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dfs(x+way[i][0],y+way[i][1]);</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(f[x+way[i][0]][y+way[i][1]] + 1 &gt; f[x][y])</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;f[x][y] = f[x+way[i][0]][y+way[i][1]] + 1;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fst=1;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(ans &lt; f[x][y])</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ans = f[x][y];</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;">}</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">void</span></div><div><span style="font-size: 12px;">doit()</span></div><div><span style="font-size: 12px;">{</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; int i,j;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp;&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; for(i=1;i&lt;=r;i++)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(j=1;j&lt;=c;j++)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dfs(i,j);</span></div><div><span style="font-size: 12px;">}</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp;</span></div><div><span style="font-size: 12px;">int</span></div><div><span style="font-size: 12px;">main()</span></div><div><span style="font-size: 12px;">{</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; freopen("hx.out","w",stdout);</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; init();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; doit();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; fst ? printf("%ld\n",ans) : printf("1\n");</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; return 0;</span></div><div><span style="font-size: 12px;">}</span></div><div><span style="font-size: 12px; ">&nbsp;PS:开数组要开大些。。。 &nbsp; &nbsp;&nbsp;</span></div><img src ="http://www.cppblog.com/slytherin/aggbug/193735.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/slytherin/" target="_blank">slytherin</a> 2012-10-23 20:22 <a href="http://www.cppblog.com/slytherin/articles/193735.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[vijos] P1501 送给圣诞夜的极光</title><link>http://www.cppblog.com/slytherin/articles/193685.html</link><dc:creator>slytherin</dc:creator><author>slytherin</author><pubDate>Mon, 22 Oct 2012 12:49:00 GMT</pubDate><guid>http://www.cppblog.com/slytherin/articles/193685.html</guid><wfw:comment>http://www.cppblog.com/slytherin/comments/193685.html</wfw:comment><comments>http://www.cppblog.com/slytherin/articles/193685.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/slytherin/comments/commentRss/193685.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/slytherin/services/trackbacks/193685.html</trackback:ping><description><![CDATA[朴素的FloodFill<br /><br /><div>#include &lt;stdio.h&gt;</div><div></div><div>int X,Y;</div><div>char a[110][110];</div><div>int vis[110][110];</div><div>int ax[15]={0,1,-1,1,-1,0,0,0,0,1,2,-1,-2};</div><div>int ay[15]={0,1,-1,-1,1,1,2,-1,-2,0,0,0,0};</div><div>long ans;</div><div></div><div>void&nbsp;</div><div>init()</div><div>{</div><div>&nbsp; &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; char s;</div><div>&nbsp; &nbsp; &nbsp; scanf("%d%d",&amp;X,&amp;Y);</div><div>&nbsp; &nbsp; &nbsp; scanf("%c",&amp;s);</div><div>&nbsp; &nbsp; &nbsp; int i,j;</div><div>&nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; for(i=1;i&lt;=X;i++)</div><div>&nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(j=1;j&lt;=Y;j++)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf("%c",&amp;a[i][j]);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf("%c",&amp;s);</div><div>&nbsp; &nbsp; &nbsp; }</div><div>}</div><div></div><div>void</div><div>dfs(int x,int y)</div><div>{</div><div>&nbsp; &nbsp;vis[x][y]=1;</div><div>&nbsp; &nbsp;int i;</div><div>&nbsp; &nbsp;int u,v;</div><div>&nbsp; &nbsp;for(i=1;i&lt;=12;i++)</div><div>&nbsp; &nbsp;{</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;u=x+ax[i];</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v=y+ay[i];</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(u&gt;=1 &amp;&amp; u&lt;= X &amp;&amp; v&gt;=1 &amp;&amp; v&lt;=Y &amp;&amp; a[u][v]=='#' &amp;&amp; !vis[u][v])</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dfs(u,v);</div><div>&nbsp; &nbsp;}&nbsp;</div><div>}</div><div></div><div>void</div><div>doit()</div><div>{</div><div>&nbsp; &nbsp; &nbsp; int i,j;</div><div>&nbsp; &nbsp; &nbsp; for(i=1;i&lt;=X;i++)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(j=1;j&lt;=Y;j++)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(!vis[i][j] &amp;&amp; a[i][j]=='#'){</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ans++;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dfs(i,j);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>} &nbsp; &nbsp;&nbsp;</div><div>&nbsp;</div><img src ="http://www.cppblog.com/slytherin/aggbug/193685.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/slytherin/" target="_blank">slytherin</a> 2012-10-22 20:49 <a href="http://www.cppblog.com/slytherin/articles/193685.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[vijos] P1681 小岛土地开发的期待</title><link>http://www.cppblog.com/slytherin/articles/193682.html</link><dc:creator>slytherin</dc:creator><author>slytherin</author><pubDate>Mon, 22 Oct 2012 12:47:00 GMT</pubDate><guid>http://www.cppblog.com/slytherin/articles/193682.html</guid><wfw:comment>http://www.cppblog.com/slytherin/comments/193682.html</wfw:comment><comments>http://www.cppblog.com/slytherin/articles/193682.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/slytherin/comments/commentRss/193682.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/slytherin/services/trackbacks/193682.html</trackback:ping><description><![CDATA[很简单的一道搜索题目，而且难度为1.但几乎没怎么写过保存路径的题目。。。所以。。。<br /><div style="text-align: -webkit-left; "><div><span style="font-size: 12px; line-height: 18px;">#include &lt;stdio.h&gt;</span></div><div><span style="font-size: 12px; line-height: 18px;">#include &lt;memory.h&gt;</span></div><div><span style="font-size: 12px; line-height: 18px;">int wayx[4]={-1,0,0,1};</span></div><div><span style="font-size: 12px; line-height: 18px;">int wayy[4]={0,-1,1,0};</span></div><div><span style="font-size: 12px; line-height: 18px;">int vis[10][10];</span></div><div><span style="font-size: 12px; line-height: 18px;">int m,n;</span></div><div><span style="font-size: 12px; line-height: 18px;">int sx,sy;</span></div><div><span style="font-size: 12px; line-height: 18px;">int a[10][10];</span></div><div><span style="font-size: 12px; line-height: 18px;">long ans;</span></div><div><span style="font-size: 12px; line-height: 18px;"><br /></span></div><div><span style="font-size: 12px; line-height: 18px;"><br /></span></div><div><span style="font-size: 12px; line-height: 18px;">struct way</span></div><div><span style="font-size: 12px; line-height: 18px;">{</span></div><div><span style="font-size: 12px; line-height: 18px;">int xx;</span></div><div><span style="font-size: 12px; line-height: 18px;">int yy;</span></div><div><span style="font-size: 12px; line-height: 18px;">}sum[30],ansxy[30];</span></div><div><span style="font-size: 12px; line-height: 18px;"><br /></span></div><div><span style="font-size: 12px; line-height: 18px;"><br /></span></div><div><span style="font-size: 12px; line-height: 18px;"><br /></span></div><div><span style="font-size: 12px; line-height: 18px;"><br /></span></div><div><span style="font-size: 12px; line-height: 18px;"><br /></span></div><div><span style="font-size: 12px; line-height: 18px;">void</span></div><div><span style="font-size: 12px; line-height: 18px;">init()</span></div><div><span style="font-size: 12px; line-height: 18px;">{</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; //freopen("one1.in","r",stdin);</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; char s;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; scanf("%d%d",&amp;m,&amp;n);</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; scanf("%c",&amp;s);</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; int i,j;</span></div><div><span style="font-size: 12px; line-height: 18px;"><br /></span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; for(i=1;i&lt;=n;i++)</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for(j=1;j&lt;=m;j++)</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf("%c",&amp;s);</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(s == 'S')</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sx = i;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sy = j;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a[i][j] = 1;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else if(s == '1')a[i][j]=1;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else if(s == '0')a[i][j]=0;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;scanf("%c",&amp;s);</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px; line-height: 18px;">}</span></div><div><span style="font-size: 12px; line-height: 18px;"><br /></span></div><div><span style="font-size: 12px; line-height: 18px;"><br /></span></div><div><span style="font-size: 12px; line-height: 18px;"><br /></span></div><div><span style="font-size: 12px; line-height: 18px;"><br /></span></div><div><span style="font-size: 12px; line-height: 18px;">void</span></div><div><span style="font-size: 12px; line-height: 18px;">dfs(int x,int y,int num)</span></div><div><span style="font-size: 12px; line-height: 18px;">{</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; int u,v;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; sum[num].xx = x;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; sum[num].yy = y;</span></div><div><span style="font-size: 12px; line-height: 18px;"><br /></span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; if(num &gt; ans)</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;memcpy(ansxy,sum,30*8);</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ans = num;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; vis[x][y]=1;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; int i;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; for(i=0;i&lt;4;i++)</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u = x + wayx[i];</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v = y + wayy[i];</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(u&lt;=n &amp;&amp; v&lt;= m&amp;&amp; u&gt;0 &amp;&amp; v&gt;0 &amp;&amp; !vis[u][v] &amp;&amp; a[u][v])</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dfs(u,v,num+1);</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; vis[x][y]=0;</span></div><div><span style="font-size: 12px; line-height: 18px;">}</span></div><div><span style="font-size: 12px; line-height: 18px;"><br /></span></div><div><span style="font-size: 12px; line-height: 18px;">void</span></div><div><span style="font-size: 12px; line-height: 18px;">write()</span></div><div><span style="font-size: 12px; line-height: 18px;">{</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; // freopen("1.out","w",stdout);</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp;printf("%ld\n",ans);</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp;int i;</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp;for(i=1;i&lt;=ans;i++)</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp;{</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("(%d,%d)\n",ansxy[i].xx,ansxy[i].yy);</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp;}</span></div><div><span style="font-size: 12px; line-height: 18px;">}</span></div><div><span style="font-size: 12px; line-height: 18px;"><br /></span></div><div><span style="font-size: 12px; line-height: 18px;">int</span></div><div><span style="font-size: 12px; line-height: 18px;">main()</span></div><div><span style="font-size: 12px; line-height: 18px;">{</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; init();</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; dfs(sx,sy,1);</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; write();</span></div><div><span style="font-size: 12px; line-height: 18px;">&nbsp; &nbsp; &nbsp; return 0;</span></div><div><span style="font-size: 12px; line-height: 18px;">}</span></div><div style="font-size: 12px; line-height: 18px; "><br />{<br />&nbsp;&nbsp;&nbsp;PS：<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1，memcpy的用法<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2，这道题目需要考虑搜索顺序<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3，注意 &nbsp; x是行，y是列 &nbsp;WA了几次<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4，在函数里。。。。。重新定义了与全局变量的局部变量。。。导致WA了很多次。。<br /></div></div><img src ="http://www.cppblog.com/slytherin/aggbug/193682.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/slytherin/" target="_blank">slytherin</a> 2012-10-22 20:47 <a href="http://www.cppblog.com/slytherin/articles/193682.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>