﻿<?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++博客-Initiate-随笔分类-搜索</title><link>http://www.cppblog.com/initiate/category/13452.html</link><description>Call A Spade a Spade</description><language>zh-cn</language><lastBuildDate>Fri, 09 Apr 2010 03:10:47 GMT</lastBuildDate><pubDate>Fri, 09 Apr 2010 03:10:47 GMT</pubDate><ttl>60</ttl><item><title>SGU134Centroid </title><link>http://www.cppblog.com/initiate/archive/2010/04/08/112002.html</link><dc:creator>Initiate</dc:creator><author>Initiate</author><pubDate>Thu, 08 Apr 2010 12:58:00 GMT</pubDate><guid>http://www.cppblog.com/initiate/archive/2010/04/08/112002.html</guid><wfw:comment>http://www.cppblog.com/initiate/comments/112002.html</wfw:comment><comments>http://www.cppblog.com/initiate/archive/2010/04/08/112002.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/initiate/comments/commentRss/112002.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/initiate/services/trackbacks/112002.html</trackback:ping><description><![CDATA[<p align=center><strong>&nbsp;&nbsp;134. Centroid </p>
</strong>
<p align=center>time limit per test: 0.50 sec. <br>memory limit per test: 4096 KB </p>
<p align=justify></p>
<p align=justify>You are given an undirected connected graph, with <strong>N</strong> vertices and <strong>N-1</strong> edges (a tree). You must find the centroid(s) of the tree. <br>In order to define the centroid, some integer value will be assosciated to every vertex. Let's consider the vertex <strong>k</strong>. If we remove the vertex <strong>k</strong> from the tree (along with its adjacent edges), the remaining graph will have only <strong>N-1</strong> vertices and may be composed of more than one connected components. Each of these components is (obviously) a tree. The value associated to vertex <strong>k</strong> is the largest number of vertices contained by some connected component in the remaining graph, after the removal of vertex <strong>k</strong>. All the vertices for which the associated value is minimum are considered centroids. </p>
<p align=justify></p>
<strong>
<p align=justify>Input</p>
</strong>
<p align=justify>The first line of the input contains the integer number <strong>N</strong> (<strong>1&lt;=N&lt;=16 000</strong>). The next <strong>N-1</strong> lines will contain two integers, <strong>a</strong> and <strong>b</strong>, separated by blanks, meaning that there exists an edge between vertex <strong>a</strong> and vertex <strong>b</strong>. </p>
<p align=justify></p>
<strong>
<p align=justify>Output</p>
</strong>
<p align=justify>You should print two lines. The first line should contain the minimum value associated to the centroid(s) and the number of centroids. The second line should contain the list of vertices which are centroids, sorted in ascending order. </p>
<p align=justify></p>
<p align=justify>Sample Input</p>
<font face="Courier New">
<pre>7
1 2
2 3
2 4
1 5
5 6
6 7
</pre>
<p align=justify></p>
</font>
<p align=justify>Sample Output</p>
<font face="Courier New">
<pre>3 1
1</pre>
<pre>给一棵n个节点的树，求这棵树的重心。<br>树的重心就是是指删掉它以后，<br>剩下的最大的连通子树的节点数是最少的点。</pre>
<pre>因为树是保证连通的，所以从任何一个节点都可以把这棵树拎起来。</pre>
<pre>所以可以从任何一个点去DFS（返回子节点个数+1）</pre>
<pre>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">algorithm</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">&nbsp;pk(x)&nbsp;push_back(x)</span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000">&nbsp;std;<br></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;N</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">16010</span><span style="COLOR: #000000">;<br>vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">g[N];&nbsp;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,value</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0x7fffffff</span><span style="COLOR: #000000">,num;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">n为边数，value为最小权值，num为重心个数&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;res[N],vis[N];<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;dfs(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;u)</span><span style="COLOR: #008000">//<br></span><span style="COLOR: #000000">{<br>&nbsp;&nbsp;&nbsp;&nbsp;vis[u]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;sum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,tmp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">k是节点u的value.Sum是u的所有子节点的个数&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">g[u].size();i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;v</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">g[u][i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">vis[v]){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">dfs(v);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum&nbsp;</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;tmp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(k</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">tmp)&nbsp;k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">tmp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">k(f[u])=max{sum[v]+1}sum[v]是v的所有子节点个数+v自己&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;tmp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">sum;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">k(f[u])=max{k,n-1-sum}</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">将该节点和该节点的所有子节点划去的剩余部分&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(k</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">tmp)&nbsp;k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">tmp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(value</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">k){</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">求所有节点中最小的权值&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">k;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">发现更小的，置num为1&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">u;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(value</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">k){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res[</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">num]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">u;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;sum</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">n);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,a,b;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">b);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g[a].pk(b);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g[b].pk(a);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;dfs(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d&nbsp;%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,value,num);<br>&nbsp;&nbsp;&nbsp;&nbsp;sort(res</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,res</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">num</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(num</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,res[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">num;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,res[i]);<br>&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>}<br></span></div>
</pre>
</font>
<img src ="http://www.cppblog.com/initiate/aggbug/112002.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/initiate/" target="_blank">Initiate</a> 2010-04-08 20:58 <a href="http://www.cppblog.com/initiate/archive/2010/04/08/112002.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ3700 Missile Defence System</title><link>http://www.cppblog.com/initiate/archive/2010/04/05/111676.html</link><dc:creator>Initiate</dc:creator><author>Initiate</author><pubDate>Mon, 05 Apr 2010 08:26:00 GMT</pubDate><guid>http://www.cppblog.com/initiate/archive/2010/04/05/111676.html</guid><wfw:comment>http://www.cppblog.com/initiate/comments/111676.html</wfw:comment><comments>http://www.cppblog.com/initiate/archive/2010/04/05/111676.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/initiate/comments/commentRss/111676.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/initiate/services/trackbacks/111676.html</trackback:ping><description><![CDATA[对于一套导弹拦截系统，它要不可以拦截上升序列，要不可以拦截下降序列，现在问最少需要多少套系统。<br>很自然的想到LIS算法，可惜在这里不能用，如果这样贪心的话<br>每套系统拦截最多的导弹和系统的数量最少没有什么直接联系，应该不会正确<br><br>而LIS中，最核心的思想在于能否将一个元素加入到序列中，只与这个序列目前的最后一个元素有关<br>这道题就用了这个关键的思想。<br>用up[k]和down[k]记录第k套上升（下降）系统目前所拦截的最后一个导弹<br>dfs(u,v,t)意味着已有u个上升，v个下降，正在处理第t个数<br><br>按理说，每拿到一个新的数字应该将它所有能放入的序列都放一遍的<br>但扩展节点时却存在一个贪心策略，大大节省了时间。<br>假设现在要把一个数放入一个上升序列，那么一定是所有能放入的上升序列中，最后一个元素最大的那一个。<br>其实想想也是，既然每个数字都要放到一个序列中，<br>对于上升序列，肯定是目前越小越有用，既然能放入大的里面，何必浪费一个小的呢<br>注意到其实up[i]按这种策略已经是排好序的了，所以只用找最先碰到的一个就行了<br><br>这样将深搜的树从一个多叉树变成了二叉树，时间效率提升很大。<br><br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000">&nbsp;std;<br></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">&nbsp;max(a,b)&nbsp;a&gt;b?a:b</span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,res,a[</span><span style="COLOR: #000000">60</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;up[</span><span style="COLOR: #000000">60</span><span style="COLOR: #000000">],down[</span><span style="COLOR: #000000">60</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;dfs(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;u,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;v,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;t)&nbsp;<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(u</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">v</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">res)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(t</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">n)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(u</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">v</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">res)res</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">u</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">v;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">找到更好的结果</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,tmp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">UP</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">u;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(up[i]</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">a[t])&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;tmp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">up[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;up[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[t];<br>&nbsp;&nbsp;&nbsp;&nbsp;dfs(max(i,u),v,t</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;up[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">tmp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">DOWN</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">v;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(down[i]</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">a[t])&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;tmp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">down[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;down[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[t];<br>&nbsp;&nbsp;&nbsp;&nbsp;dfs(u,max(i,v),t</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;down[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">tmp;<br>}<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">n)&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;n)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[i]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dfs(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,res);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br></span></div>
<img src ="http://www.cppblog.com/initiate/aggbug/111676.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/initiate/" target="_blank">Initiate</a> 2010-04-05 16:26 <a href="http://www.cppblog.com/initiate/archive/2010/04/05/111676.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>