﻿<?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++博客-yzhw@ujs code my life~-随笔分类-data struct</title><link>http://www.cppblog.com/yzhw/category/15166.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 22 Feb 2012 21:29:03 GMT</lastBuildDate><pubDate>Wed, 22 Feb 2012 21:29:03 GMT</pubDate><ttl>60</ttl><item><title>pku3908 并查集的一点小变通</title><link>http://www.cppblog.com/yzhw/archive/2012/02/22/166244.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Wed, 22 Feb 2012 07:58:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2012/02/22/166244.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/166244.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2012/02/22/166244.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/166244.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/166244.html</trackback:ping><description><![CDATA[题目大意这样，给出一些节点，给出3种命令：<br />1、将a,b联通<br />2、查询a,b的联通状况<br />3、删除链接a的边。（如果之前a,c通过b联通，那么删除b的联通关系后a,c仍然认为联通）<br />1，2两种操作乍一看MS是并查集，但是第三种状况让人很恼火，尤其是想用路径压缩技巧的时候。那么，我们不妨转换下思路，删除a的联通关系可以认为将a节点重标号，把之前那个a节点认为是虚拟节点，这样联通性啥的都好保证了。详细请看代码：<br /><div style="display: inline-block; "><div><p align="center" style="font-family: 'AR PL UKai CN'; line-height: normal; font-size: medium; "><font size="4" color="#333399">Source Code</font></p><table align="center" style="font-family: 'AR PL UKai CN'; font-size: 10pt; "><tbody><tr><td><strong>Problem:</strong>&nbsp;<a href="http://poj.org/problem?id=3908">3908</a></td><td width="10px"></td><td><strong>User:</strong>&nbsp;<a href="http://poj.org/userstatus?user_id=yzhw">yzhw</a></td></tr><tr><td><strong>Memory:</strong>&nbsp;1096K</td><td width="10px"></td><td><strong>Time:</strong>&nbsp;47MS</td></tr><tr><td><strong>Language:</strong>&nbsp;G++</td><td width="10px"></td><td><strong>Result:</strong>&nbsp;<font color="blue">Accepted</font></td></tr></tbody></table><ul style="font-family: 'AR PL UKai CN'; line-height: normal; font-size: medium; "><li><font color="#333399" size="5">Source Code</font></li><pre class="sh_cpp sh_sourceCode" style="background-color: white; font-family: 'Courier New', Courier, monospace; "><span class="sh_preproc" style="color: #00008b; font-weight: bold; "># include</span> <span class="sh_string" style="color: red; font-family: monospace; ">&lt;cstdio&gt;</span>
<span class="sh_preproc" style="color: #00008b; font-weight: bold; "># define</span> N <span class="sh_number" style="color: purple; ">100000</span>
<span class="sh_keyword" style="color: blue; font-weight: bold; ">using</span> <span class="sh_keyword" style="color: blue; font-weight: bold; ">namespace</span> std<span class="sh_symbol" style="color: #8b0000; ">;</span>
<span class="sh_type" style="color: #006400; ">int</span> set<span class="sh_symbol" style="color: #8b0000; ">[</span>N<span class="sh_symbol" style="color: #8b0000; ">],</span>id<span class="sh_symbol" style="color: #8b0000; ">[</span>N<span class="sh_symbol" style="color: #8b0000; ">];</span>
<span class="sh_type" style="color: #006400; ">int</span> <span class="sh_function" style="font-weight: bold; ">find</span><span class="sh_symbol" style="color: #8b0000; ">(</span><span class="sh_type" style="color: #006400; ">int</span> pos<span class="sh_symbol" style="color: #8b0000; ">)</span>
<span class="sh_cbracket" style="color: red; ">{</span>
	<span class="sh_keyword" style="color: blue; font-weight: bold; ">if</span><span class="sh_symbol" style="color: #8b0000; ">(</span>set<span class="sh_symbol" style="color: #8b0000; ">[</span>pos<span class="sh_symbol" style="color: #8b0000; ">]==</span>pos<span class="sh_symbol" style="color: #8b0000; ">)</span> <span class="sh_keyword" style="color: blue; font-weight: bold; ">return</span> pos<span class="sh_symbol" style="color: #8b0000; ">;</span>
	<span class="sh_keyword" style="color: blue; font-weight: bold; ">else</span> <span class="sh_keyword" style="color: blue; font-weight: bold; ">return</span> set<span class="sh_symbol" style="color: #8b0000; ">[</span>pos<span class="sh_symbol" style="color: #8b0000; ">]=</span><span class="sh_function" style="font-weight: bold; ">find</span><span class="sh_symbol" style="color: #8b0000; ">(</span>set<span class="sh_symbol" style="color: #8b0000; ">[</span>pos<span class="sh_symbol" style="color: #8b0000; ">]);</span>
<span class="sh_cbracket" style="color: red; ">}</span>
<span class="sh_type" style="color: #006400; ">void</span> <span class="sh_function" style="font-weight: bold; ">uni</span><span class="sh_symbol" style="color: #8b0000; ">(</span><span class="sh_type" style="color: #006400; ">int</span> a<span class="sh_symbol" style="color: #8b0000; ">,</span><span class="sh_type" style="color: #006400; ">int</span> b<span class="sh_symbol" style="color: #8b0000; ">)</span>
<span class="sh_cbracket" style="color: red; ">{</span>
	set<span class="sh_symbol" style="color: #8b0000; ">[</span><span class="sh_function" style="font-weight: bold; ">find</span><span class="sh_symbol" style="color: #8b0000; ">(</span>a<span class="sh_symbol" style="color: #8b0000; ">)]=</span><span class="sh_function" style="font-weight: bold; ">find</span><span class="sh_symbol" style="color: #8b0000; ">(</span>b<span class="sh_symbol" style="color: #8b0000; ">);</span>
<span class="sh_cbracket" style="color: red; ">}</span>
<span class="sh_type" style="color: #006400; ">int</span> <span class="sh_function" style="font-weight: bold; ">main</span><span class="sh_symbol" style="color: #8b0000; ">()</span>
<span class="sh_cbracket" style="color: red; ">{</span>
	<span class="sh_type" style="color: #006400; ">int</span> num<span class="sh_symbol" style="color: #8b0000; ">;</span>
	<span class="sh_keyword" style="color: blue; font-weight: bold; ">while</span><span class="sh_symbol" style="color: #8b0000; ">(</span><span class="sh_function" style="font-weight: bold; ">scanf</span><span class="sh_symbol" style="color: #8b0000; ">(</span><span class="sh_string" style="color: red; font-family: monospace; ">"%d"</span><span class="sh_symbol" style="color: #8b0000; ">,&amp;</span>num<span class="sh_symbol" style="color: #8b0000; ">)!=</span>EOF<span class="sh_symbol" style="color: #8b0000; ">)</span>
	<span class="sh_cbracket" style="color: red; ">{</span>
		<span class="sh_type" style="color: #006400; ">int</span> c<span class="sh_symbol" style="color: #8b0000; ">=</span>num<span class="sh_number" style="color: purple; ">+1</span><span class="sh_symbol" style="color: #8b0000; ">,</span>n1<span class="sh_symbol" style="color: #8b0000; ">=</span><span class="sh_number" style="color: purple; ">0</span><span class="sh_symbol" style="color: #8b0000; ">,</span>n2<span class="sh_symbol" style="color: #8b0000; ">=</span><span class="sh_number" style="color: purple; ">0</span><span class="sh_symbol" style="color: #8b0000; ">;</span>
		<span class="sh_keyword" style="color: blue; font-weight: bold; ">for</span><span class="sh_symbol" style="color: #8b0000; ">(</span><span class="sh_type" style="color: #006400; ">int</span> i<span class="sh_symbol" style="color: #8b0000; ">=</span><span class="sh_number" style="color: purple; ">1</span><span class="sh_symbol" style="color: #8b0000; ">;</span>i<span class="sh_symbol" style="color: #8b0000; ">&lt;</span>N<span class="sh_symbol" style="color: #8b0000; ">;</span>i<span class="sh_symbol" style="color: #8b0000; ">++)</span> set<span class="sh_symbol" style="color: #8b0000; ">[</span>i<span class="sh_symbol" style="color: #8b0000; ">]=</span>i<span class="sh_symbol" style="color: #8b0000; ">;</span>
		<span class="sh_keyword" style="color: blue; font-weight: bold; ">for</span><span class="sh_symbol" style="color: #8b0000; ">(</span><span class="sh_type" style="color: #006400; ">int</span> i<span class="sh_symbol" style="color: #8b0000; ">=</span><span class="sh_number" style="color: purple; ">1</span><span class="sh_symbol" style="color: #8b0000; ">;</span>i<span class="sh_symbol" style="color: #8b0000; ">&lt;=</span>num<span class="sh_symbol" style="color: #8b0000; ">;</span>i<span class="sh_symbol" style="color: #8b0000; ">++)</span> id<span class="sh_symbol" style="color: #8b0000; ">[</span>i<span class="sh_symbol" style="color: #8b0000; ">]=</span>i<span class="sh_symbol" style="color: #8b0000; ">;</span>
		<span class="sh_type" style="color: #006400; ">char</span> jud<span class="sh_symbol" style="color: #8b0000; ">[</span><span class="sh_number" style="color: purple; ">5</span><span class="sh_symbol" style="color: #8b0000; ">];</span>
		<span class="sh_keyword" style="color: blue; font-weight: bold; ">while</span><span class="sh_symbol" style="color: #8b0000; ">(</span><span class="sh_function" style="font-weight: bold; ">scanf</span><span class="sh_symbol" style="color: #8b0000; ">(</span><span class="sh_string" style="color: red; font-family: monospace; ">"%s"</span><span class="sh_symbol" style="color: #8b0000; ">,</span>jud<span class="sh_symbol" style="color: #8b0000; ">)&amp;&amp;*</span>jud<span class="sh_symbol" style="color: #8b0000; ">!=</span><span class="sh_string" style="color: red; font-family: monospace; ">'e'</span><span class="sh_symbol" style="color: #8b0000; ">)</span>
		<span class="sh_cbracket" style="color: red; ">{</span>
			<span class="sh_type" style="color: #006400; ">int</span> a<span class="sh_symbol" style="color: #8b0000; ">,</span>b<span class="sh_symbol" style="color: #8b0000; ">;</span>
			<span class="sh_keyword" style="color: blue; font-weight: bold; ">switch</span><span class="sh_symbol" style="color: #8b0000; ">(*</span>jud<span class="sh_symbol" style="color: #8b0000; ">)</span>
			<span class="sh_cbracket" style="color: red; ">{</span>
			<span class="sh_keyword" style="color: blue; font-weight: bold; ">case</span> <span class="sh_string" style="color: red; font-family: monospace; ">'c'</span><span class="sh_symbol" style="color: #8b0000; ">:</span>
				<span class="sh_function" style="font-weight: bold; ">scanf</span><span class="sh_symbol" style="color: #8b0000; ">(</span><span class="sh_string" style="color: red; font-family: monospace; ">"%d%d"</span><span class="sh_symbol" style="color: #8b0000; ">,&amp;</span>a<span class="sh_symbol" style="color: #8b0000; ">,&amp;</span>b<span class="sh_symbol" style="color: #8b0000; ">);</span>
				<span class="sh_function" style="font-weight: bold; ">uni</span><span class="sh_symbol" style="color: #8b0000; ">(</span>id<span class="sh_symbol" style="color: #8b0000; ">[</span>a<span class="sh_symbol" style="color: #8b0000; ">],</span>id<span class="sh_symbol" style="color: #8b0000; ">[</span>b<span class="sh_symbol" style="color: #8b0000; ">]);</span>
				<span class="sh_keyword" style="color: blue; font-weight: bold; ">break</span><span class="sh_symbol" style="color: #8b0000; ">;</span>
			<span class="sh_keyword" style="color: blue; font-weight: bold; ">case</span> <span class="sh_string" style="color: red; font-family: monospace; ">'d'</span><span class="sh_symbol" style="color: #8b0000; ">:</span>
				<span class="sh_function" style="font-weight: bold; ">scanf</span><span class="sh_symbol" style="color: #8b0000; ">(</span><span class="sh_string" style="color: red; font-family: monospace; ">"%d"</span><span class="sh_symbol" style="color: #8b0000; ">,&amp;</span>a<span class="sh_symbol" style="color: #8b0000; ">);</span>
				id<span class="sh_symbol" style="color: #8b0000; ">[</span>a<span class="sh_symbol" style="color: #8b0000; ">]=</span>c<span class="sh_symbol" style="color: #8b0000; ">++;</span>
				<span class="sh_keyword" style="color: blue; font-weight: bold; ">break</span><span class="sh_symbol" style="color: #8b0000; ">;</span>
			<span class="sh_keyword" style="color: blue; font-weight: bold; ">case</span> <span class="sh_string" style="color: red; font-family: monospace; ">'q'</span><span class="sh_symbol" style="color: #8b0000; ">:</span>
				<span class="sh_function" style="font-weight: bold; ">scanf</span><span class="sh_symbol" style="color: #8b0000; ">(</span><span class="sh_string" style="color: red; font-family: monospace; ">"%d%d"</span><span class="sh_symbol" style="color: #8b0000; ">,&amp;</span>a<span class="sh_symbol" style="color: #8b0000; ">,&amp;</span>b<span class="sh_symbol" style="color: #8b0000; ">);</span>
				<span class="sh_keyword" style="color: blue; font-weight: bold; ">if</span><span class="sh_symbol" style="color: #8b0000; ">(</span><span class="sh_function" style="font-weight: bold; ">find</span><span class="sh_symbol" style="color: #8b0000; ">(</span>id<span class="sh_symbol" style="color: #8b0000; ">[</span>a<span class="sh_symbol" style="color: #8b0000; ">])==</span><span class="sh_function" style="font-weight: bold; ">find</span><span class="sh_symbol" style="color: #8b0000; ">(</span>id<span class="sh_symbol" style="color: #8b0000; ">[</span>b<span class="sh_symbol" style="color: #8b0000; ">]))</span> n1<span class="sh_symbol" style="color: #8b0000; ">++;</span>
				<span class="sh_keyword" style="color: blue; font-weight: bold; ">else</span> n2<span class="sh_symbol" style="color: #8b0000; ">++;</span>
				<span class="sh_keyword" style="color: blue; font-weight: bold; ">break</span><span class="sh_symbol" style="color: #8b0000; ">;</span>
			<span class="sh_cbracket" style="color: red; ">}</span><span class="sh_symbol" style="color: #8b0000; ">;</span>

		<span class="sh_cbracket" style="color: red; ">}</span>
		<span class="sh_function" style="font-weight: bold; ">printf</span><span class="sh_symbol" style="color: #8b0000; ">(</span><span class="sh_string" style="color: red; font-family: monospace; ">"%d , %d</span><span class="sh_specialchar" style="color: #ffc0cb; font-family: monospace; ">\n</span><span class="sh_string" style="color: red; font-family: monospace; ">"</span><span class="sh_symbol" style="color: #8b0000; ">,</span>n1<span class="sh_symbol" style="color: #8b0000; ">,</span>n2<span class="sh_symbol" style="color: #8b0000; ">);</span>
	<span class="sh_cbracket" style="color: red; ">}</span>
	<span class="sh_keyword" style="color: blue; font-weight: bold; ">return</span> <span class="sh_number" style="color: purple; ">0</span><span class="sh_symbol" style="color: #8b0000; ">;</span>
<span class="sh_cbracket" style="color: red; ">}</span></pre></ul></div></div><img src ="http://www.cppblog.com/yzhw/aggbug/166244.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2012-02-22 15:58 <a href="http://www.cppblog.com/yzhw/archive/2012/02/22/166244.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku 3943 Digits on the Floor 并查集的活用（重点）+数字识别</title><link>http://www.cppblog.com/yzhw/archive/2012/01/14/164184.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Sat, 14 Jan 2012 11:57:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2012/01/14/164184.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/164184.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2012/01/14/164184.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/164184.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/164184.html</trackback:ping><description><![CDATA[题意很简单，给出一些线段，组成一些数字，保持数字连接点的联通关系不变（就说是图的逻辑结构不变吧），并且保证没有相交。要求识别数字。<br />首先这题，涉及到并查集的运用。开始犯了个很糊涂的错误，本题新加上一条线段可能造成2种情况<br />1、A - C，新加线为C，就是把C连接到某个树枝上<br />2、A-C-B，这种情况考虑漏了，就是通过C这个线把俩个不连通的集合给打通了<br />具体代码应该是这样<br />for(int j=0;j&lt;now;j++)<br />&nbsp; &nbsp; if(find(now)!=find(j)&amp;&amp;cross(now,j))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set[find(now)]=find(j);<br />开始糊涂蛋的写成了<br />for(int j=0;j&lt;now;j++)<br />&nbsp; &nbsp; &nbsp; if(cross(now,j))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set[now]=find(j),break;<br />这个就是只考虑了第一种情况。<br /><br />关于数字识别的问题就好办多了，主要根据部分相交和点相交的数目以及联通集中线段的数目来判断数字（5和2还要根据叉积再来弄下），这题受益最深的就是并查集那里，容易犯的错误。<br /><br />代码如下：<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; ">&nbsp; 1</span>&nbsp;Source&nbsp;Code<br /><span style="color: #008080; ">&nbsp;&nbsp;2</span>&nbsp;<br /><span style="color: #008080; ">&nbsp;&nbsp;3</span>&nbsp;Problem:&nbsp;3943&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User:&nbsp;yzhw<br /><span style="color: #008080; ">&nbsp;&nbsp;4</span>&nbsp;Memory:&nbsp;656K&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Time:&nbsp;188MS<br /><span style="color: #008080; ">&nbsp;&nbsp;5</span>&nbsp;Language:&nbsp;G++&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Result:&nbsp;Accepted<br /><span style="color: #008080; ">&nbsp;&nbsp;6</span>&nbsp;Source&nbsp;Code<br /><span style="color: #008080; ">&nbsp;&nbsp;7</span>&nbsp;#&nbsp;include&nbsp;&lt;cstdio&gt;<br /><span style="color: #008080; ">&nbsp;&nbsp;8</span>&nbsp;#&nbsp;include&nbsp;&lt;vector&gt;<br /><span style="color: #008080; ">&nbsp;&nbsp;9</span>&nbsp;#&nbsp;include&nbsp;&lt;cstring&gt;<br /><span style="color: #008080; ">&nbsp;10</span>&nbsp;#&nbsp;include&nbsp;&lt;map&gt;<br /><span style="color: #008080; ">&nbsp;11</span>&nbsp;<span style="color: #0000FF; ">using</span>&nbsp;<span style="color: #0000FF; ">namespace</span>&nbsp;std;<br /><span style="color: #008080; ">&nbsp;12</span>&nbsp;#&nbsp;define&nbsp;N&nbsp;1005<br /><span style="color: #008080; ">&nbsp;13</span>&nbsp;#&nbsp;define&nbsp;min(a,b)&nbsp;((a)&lt;(b)?(a):(b))<br /><span style="color: #008080; ">&nbsp;14</span>&nbsp;#&nbsp;define&nbsp;max(a,b)&nbsp;((a)&gt;(b)?(a):(b))<br /><span style="color: #008080; ">&nbsp;15</span>&nbsp;<span style="color: #0000FF; ">struct</span>&nbsp;line<br /><span style="color: #008080; ">&nbsp;16</span>&nbsp;{<br /><span style="color: #008080; ">&nbsp;17</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;x1,y1,x2,y2;<br /><span style="color: #008080; ">&nbsp;18</span>&nbsp;}l[N];<br /><span style="color: #008080; ">&nbsp;19</span>&nbsp;<span style="color: #0000FF; ">bool</span>&nbsp;<span style="color: #0000FF; ">in</span>(<span style="color: #0000FF; ">int</span>&nbsp;x,<span style="color: #0000FF; ">int</span>&nbsp;y,<span style="color: #0000FF; ">const</span>&nbsp;line&nbsp;&amp;pos)<br /><span style="color: #008080; ">&nbsp;20</span>&nbsp;{<br /><span style="color: #008080; ">&nbsp;21</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(x&gt;=min(pos.x1,pos.x2)&amp;&amp;x&lt;=max(pos.x1,pos.x2)&amp;&amp;<br /><span style="color: #008080; ">&nbsp;22</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y&gt;=min(pos.y1,pos.y2)&amp;&amp;y&lt;=max(pos.y1,pos.y2)&amp;&amp;<br /><span style="color: #008080; ">&nbsp;23</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(pos.y2-pos.y1)*(pos.x2-x)==(pos.x2-pos.x1)*(pos.y2-y))<br /><span style="color: #008080; ">&nbsp;24</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;<span style="color: #0000FF; ">true</span>;<br /><span style="color: #008080; ">&nbsp;25</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">else</span>&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;<span style="color: #0000FF; ">false</span>;<br /><span style="color: #008080; ">&nbsp;26</span>&nbsp;}<br /><span style="color: #008080; ">&nbsp;27</span>&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;cross(<span style="color: #0000FF; ">const</span>&nbsp;line&nbsp;&amp;a,<span style="color: #0000FF; ">const</span>&nbsp;line&nbsp;&amp;b)<br /><span style="color: #008080; ">&nbsp;28</span>&nbsp;{<br /><span style="color: #008080; ">&nbsp;29</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(a.x1==b.x1&amp;&amp;a.y1==b.y1||<br /><span style="color: #008080; ">&nbsp;30</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a.x2==b.x1&amp;&amp;a.y2==b.y1||<br /><span style="color: #008080; ">&nbsp;31</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a.x1==b.x2&amp;&amp;a.y1==b.y2||<br /><span style="color: #008080; ">&nbsp;32</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a.x2==b.x2&amp;&amp;a.y2==b.y2)&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;1;<br /><span style="color: #008080; ">&nbsp;33</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">else</span>&nbsp;<span style="color: #0000FF; ">if</span>(<span style="color: #0000FF; ">in</span>(a.x1,a.y1,b)||<span style="color: #0000FF; ">in</span>(a.x2,a.y2,b)||<span style="color: #0000FF; ">in</span>(b.x1,b.y1,a)||<span style="color: #0000FF; ">in</span>(b.x2,b.y2,a))&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;2;<br /><span style="color: #008080; ">&nbsp;34</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">else</span>&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;0;<br /><span style="color: #008080; ">&nbsp;35</span>&nbsp;}<br /><span style="color: #008080; ">&nbsp;36</span>&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;cross(<span style="color: #0000FF; ">int</span>&nbsp;x1,<span style="color: #0000FF; ">int</span>&nbsp;y1,<span style="color: #0000FF; ">int</span>&nbsp;x2,<span style="color: #0000FF; ">int</span>&nbsp;y2)<br /><span style="color: #008080; ">&nbsp;37</span>&nbsp;{<br /><span style="color: #008080; ">&nbsp;38</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;x1*y2-x2*y1;<br /><span style="color: #008080; ">&nbsp;39</span>&nbsp;}<br /><span style="color: #008080; ">&nbsp;40</span>&nbsp;<span style="color: #0000FF; ">struct</span>&nbsp;node<br /><span style="color: #008080; ">&nbsp;41</span>&nbsp;{<br /><span style="color: #008080; ">&nbsp;42</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vector&lt;line&gt;&nbsp;data;<br /><span style="color: #008080; ">&nbsp;43</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;type()&nbsp;<span style="color: #0000FF; ">const</span><br /><span style="color: #008080; ">&nbsp;44</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /><span style="color: #008080; ">&nbsp;45</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;num[3]={0,0,0};<br /><span style="color: #008080; ">&nbsp;46</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span>&nbsp;i=0;i&lt;data.size();i++)<br /><span style="color: #008080; ">&nbsp;47</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span>&nbsp;j=i+1;j&lt;data.size();j++)<br /><span style="color: #008080; ">&nbsp;48</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num[cross(data[i],data[j])]++;<br /><span style="color: #008080; ">&nbsp;49</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(num[1]==4&amp;&amp;num[2]==0)<br /><span style="color: #008080; ">&nbsp;50</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /><span style="color: #008080; ">&nbsp;51</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(data.size()==4)&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;0;<br /><span style="color: #008080; ">&nbsp;52</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">else</span><br /><span style="color: #008080; ">&nbsp;53</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /><span style="color: #008080; ">&nbsp;54</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;target=-1,x1,y1,x2,y2;<br /><span style="color: #008080; ">&nbsp;55</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span>&nbsp;i=0;i&lt;data.size();i++)<br /><span style="color: #008080; ">&nbsp;56</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /><span style="color: #008080; ">&nbsp;57</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">bool</span>&nbsp;flag=<span style="color: #0000FF; ">true</span>;<br /><span style="color: #008080; ">&nbsp;58</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span>&nbsp;j=0;j&lt;data.size()&amp;&amp;flag;j++)<br /><span style="color: #008080; ">&nbsp;59</span>&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 style="color: #0000FF; ">if</span>(j!=i&amp;&amp;(data[i].x1==data[j].x1&amp;&amp;data[i].y1==data[j].y1||data[i].x1==data[j].x2&amp;&amp;data[i].y1==data[j].y2))<br /><span style="color: #008080; ">&nbsp;60</span>&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;flag=<span style="color: #0000FF; ">false</span>;<br /><span style="color: #008080; ">&nbsp;61</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(flag)<br /><span style="color: #008080; ">&nbsp;62</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /><span style="color: #008080; ">&nbsp;63</span>&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;target=i;<br /><span style="color: #008080; ">&nbsp;64</span>&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;x1=data[i].x2,y1=data[i].y2;<br /><span style="color: #008080; ">&nbsp;65</span>&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;x2=data[i].x1,y2=data[i].y1;<br /><span style="color: #008080; ">&nbsp;66</span>&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 style="color: #0000FF; ">break</span>;<br /><span style="color: #008080; ">&nbsp;67</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">&nbsp;68</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flag=<span style="color: #0000FF; ">true</span>;<br /><span style="color: #008080; ">&nbsp;69</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span>&nbsp;j=0;j&lt;data.size()&amp;&amp;flag;j++)<br /><span style="color: #008080; ">&nbsp;70</span>&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 style="color: #0000FF; ">if</span>(j!=i&amp;&amp;(data[i].x2==data[j].x1&amp;&amp;data[i].y2==data[j].y1||data[i].x2==data[j].x2&amp;&amp;data[i].y2==data[j].y2))<br /><span style="color: #008080; ">&nbsp;71</span>&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;flag=<span style="color: #0000FF; ">false</span>;<br /><span style="color: #008080; ">&nbsp;72</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(flag)<br /><span style="color: #008080; ">&nbsp;73</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /><span style="color: #008080; ">&nbsp;74</span>&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;target=i;<br /><span style="color: #008080; ">&nbsp;75</span>&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;x1=data[i].x1,y1=data[i].y1;<br /><span style="color: #008080; ">&nbsp;76</span>&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;x2=data[i].x2,y2=data[i].y2;<br /><span style="color: #008080; ">&nbsp;77</span>&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 style="color: #0000FF; ">break</span>;<br /><span style="color: #008080; ">&nbsp;78</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">&nbsp;79</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">&nbsp;80</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span>&nbsp;i=0;i&lt;data.size();i++)<br /><span style="color: #008080; ">&nbsp;81</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(i!=target)<br /><span style="color: #008080; ">&nbsp;82</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /><span style="color: #008080; ">&nbsp;83</span>&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 style="color: #0000FF; ">if</span>(data[i].x1==x1&amp;&amp;data[i].y1==y1)<br /><span style="color: #008080; ">&nbsp;84</span>&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 style="color: #0000FF; ">return</span>&nbsp;cross(data[i].x2-data[i].x1,data[i].y2-data[i].y1,x1-x2,y1-y2)&lt;0?5:2;<br /><span style="color: #008080; ">&nbsp;85</span>&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 style="color: #0000FF; ">else</span>&nbsp;<span style="color: #0000FF; ">if</span>(data[i].x2==x1&amp;&amp;data[i].y2==y1)<br /><span style="color: #008080; ">&nbsp;86</span>&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 style="color: #0000FF; ">return</span>&nbsp;cross(data[i].x1-data[i].x2,data[i].y1-data[i].y2,x1-x2,y1-y2)&lt;0?5:2;<br /><span style="color: #008080; ">&nbsp;87</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">&nbsp;88</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">&nbsp;89</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("wa!\n");<br /><span style="color: #008080; ">&nbsp;90</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">while</span>(<span style="color: #0000FF; ">true</span>);<br /><span style="color: #008080; ">&nbsp;91</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">&nbsp;92</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">else</span>&nbsp;<span style="color: #0000FF; ">if</span>(num[1]==0&amp;&amp;num[2]==0)<br /><span style="color: #008080; ">&nbsp;93</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;1;<br /><span style="color: #008080; ">&nbsp;94</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">else</span>&nbsp;<span style="color: #0000FF; ">if</span>(num[1]==4&amp;&amp;num[2]==0)<br /><span style="color: #008080; ">&nbsp;95</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;2;<br /><span style="color: #008080; ">&nbsp;96</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">else</span>&nbsp;<span style="color: #0000FF; ">if</span>(num[1]==2&amp;&amp;num[2]==1)<br /><span style="color: #008080; ">&nbsp;97</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;3;<br /><span style="color: #008080; ">&nbsp;98</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">else</span>&nbsp;<span style="color: #0000FF; ">if</span>(num[1]==1&amp;&amp;num[2]==1)<br /><span style="color: #008080; ">&nbsp;99</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;4;<br /><span style="color: #008080; ">100</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">else</span>&nbsp;<span style="color: #0000FF; ">if</span>(num[1]==4&amp;&amp;num[2]==1)<br /><span style="color: #008080; ">101</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;6;<br /><span style="color: #008080; ">102</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">else</span>&nbsp;<span style="color: #0000FF; ">if</span>(num[1]==2&amp;&amp;num[2]==0)<br /><span style="color: #008080; ">103</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;7;<br /><span style="color: #008080; ">104</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">else</span>&nbsp;<span style="color: #0000FF; ">if</span>(num[1]==4&amp;&amp;num[2]==2)<br /><span style="color: #008080; ">105</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;8;<br /><span style="color: #008080; ">106</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">else</span>&nbsp;<span style="color: #0000FF; ">if</span>(num[1]==3&amp;&amp;num[2]==1)<br /><span style="color: #008080; ">107</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;9;<br /><span style="color: #008080; ">108</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">109</span>&nbsp;};<br /><span style="color: #008080; ">110</span>&nbsp;map&lt;<span style="color: #0000FF; ">int</span>,node&gt;&nbsp;data;<br /><span style="color: #008080; ">111</span>&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;n,<span style="color: #0000FF; ">set</span>[N],ans[10];<br /><span style="color: #008080; ">112</span>&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;find(<span style="color: #0000FF; ">int</span>&nbsp;pos)<br /><span style="color: #008080; ">113</span>&nbsp;{<br /><span style="color: #008080; ">114</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(<span style="color: #0000FF; ">set</span>[pos]==pos)&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;pos;<br /><span style="color: #008080; ">115</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">else</span>&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;<span style="color: #0000FF; ">set</span>[pos]=find(<span style="color: #0000FF; ">set</span>[pos]);<br /><span style="color: #008080; ">116</span>&nbsp;}<br /><span style="color: #008080; ">117</span>&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;main()<br /><span style="color: #008080; ">118</span>&nbsp;{<br /><span style="color: #008080; ">119</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">while</span>(scanf("%d",&amp;n)!=EOF&amp;&amp;n)<br /><span style="color: #008080; ">120</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /><span style="color: #008080; ">121</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data.clear();<br /><span style="color: #008080; ">122</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(ans,0,<span style="color: #0000FF; ">sizeof</span>(ans));<br /><span style="color: #008080; ">123</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span>&nbsp;i=0;i&lt;n;i++)<br /><span style="color: #008080; ">124</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /><span style="color: #008080; ">125</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">set</span>[i]=i;<br /><span style="color: #008080; ">126</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf("%d%d%d%d",&amp;l[i].x1,&amp;l[i].y1,&amp;l[i].x2,&amp;l[i].y2);<br /><span style="color: #008080; ">127</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span>&nbsp;j=0;j&lt;i;j++)<br /><span style="color: #008080; ">128</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(cross(l[i],l[j])&amp;&amp;find(i)!=find(j))<br /><span style="color: #008080; ">129</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">set</span>[find(i)]=find(j);<br /><span style="color: #008080; ">130</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">131</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span>&nbsp;i=0;i&lt;n;i++)<br /><span style="color: #008080; ">132</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data[find(i)].data.push_back(l[i]);<br /><span style="color: #008080; ">133</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>(map&lt;<span style="color: #0000FF; ">int</span>,node&gt;::iterator&nbsp;i=data.begin();i!=data.end();i++)<br /><span style="color: #008080; ">134</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[i-&gt;second.type()]++;<br /><span style="color: #008080; ">135</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("%d",ans[0]);<br /><span style="color: #008080; ">136</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span>&nbsp;i=1;i&lt;10;i++)<br /><span style="color: #008080; ">137</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("&nbsp;%d",ans[i]);<br /><span style="color: #008080; ">138</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("\n");<br /><span style="color: #008080; ">139</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">140</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;0;<br /><span style="color: #008080; ">141</span>&nbsp;}</div><img src ="http://www.cppblog.com/yzhw/aggbug/164184.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2012-01-14 19:57 <a href="http://www.cppblog.com/yzhw/archive/2012/01/14/164184.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>2010 天津赛区G hdu 3726 splay </title><link>http://www.cppblog.com/yzhw/archive/2011/09/30/157191.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Fri, 30 Sep 2011 00:51:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/09/30/157191.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/157191.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/09/30/157191.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/157191.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/157191.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 哎，一道裸splay的题目，网上竟然木有解题报告。我第一次写splay，犯了很多很多NC的错误。。调了有一个下午，最后写了个测试模块+生成了随机数据，才发现错误。说说我的失误吧。。1、首先zig zag实现的时候一定要配对，不能乱，加个儿子节点就要把儿子节点的父亲节点同时初始化好2、新加入节点的size域及其祖先的size域名不用调整，会在splay过程中自动修正完毕3、千万别要试图将一颗子树的根...&nbsp;&nbsp;<a href='http://www.cppblog.com/yzhw/archive/2011/09/30/157191.html'>阅读全文</a><img src ="http://www.cppblog.com/yzhw/aggbug/157191.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-09-30 08:51 <a href="http://www.cppblog.com/yzhw/archive/2011/09/30/157191.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>2010 ICPC天津赛区 J hdu 3727 划分树的理解</title><link>http://www.cppblog.com/yzhw/archive/2011/09/30/157189.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Fri, 30 Sep 2011 00:44:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/09/30/157189.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/157189.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/09/30/157189.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/157189.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/157189.html</trackback:ping><description><![CDATA[很久不写划分树了，果然各种NC错误<br />按照我的理解，划分树即一个线段树（用来确定数组下标和层次）以及一个log2(n)*n的数组，来记录划分信息<br />这题实现4个操作：<br />1、插入<br />按照划分树的定义，如果小于有序表中中间节点的值，就递归插入左子树，否则递归插入右子树。更新当前区间段的划分信息（无非就是往后计算一个）<br />2、询问s,e区间第k小数<br />查询s,e区间里面划分到左子树的个数i，如果i&gt;=k，那么显然递归到左子树查询，否则就是递归到右子树查询k-i小的数。注意！这里要重新定位左子树和右子树中的区间，由于是闭区间，那么做端点为s+sum(s-1),右端点为s+sum(e)-1，这个减一丢了。。调了我半天。。哎。。以前写都是左闭右开区间的，结果习惯了。。<br />3、查询值为k的数的位次<br />这个需要一个辅助数组，记录值为k的数插在最顶层区间的哪个位置了。这个办好后，就容易了，如果数被划分到了左子树，那么递归查询左子树，否则返回递归查询右子树的值加上当前区间被划分到左子树的个数<br />4、查询rank k的数<br />同样是这样，如果当前区间被划分到左子树的个数小于等于k，那么递归查询左子树，否则递归查询右子树中rank为k-左子树的size。<br />大概思想就是这样了，实现有很多细节，比如说假设p==区间左端点（左区间木有数），那么算sum(p-1)的时候就要特判下了。我喜欢用三元式，很方便。<br /><br />代码<br /><font color="#0000ff"># include &lt;cstdio&gt;<br /># include &lt;cstring&gt;<br /># include &lt;map&gt;<br /><strong>using namespace</strong></font> std<strong><font color="#ff00ff">;</font></strong><font color="blue"><br /># define N 100005<br /></font><strong><font color="blue">int</font></strong> arr<strong><font color="#ff00ff">[</font></strong><font color="#cc3300">20</font><strong><font color="#ff00ff">][</font></strong>N<strong><font color="#ff00ff">];</font></strong><strong><font color="#0000ff"><br />struct</font></strong> node<strong><font color="#ff00ff"><br />{</font></strong><strong><font color="blue"><br />&nbsp;&nbsp; int</font></strong> s<strong><font color="#ff00ff">,</font></strong>e<strong><font color="#ff00ff">,</font></strong>layer<strong><font color="#ff00ff">;</font></strong><strong><font color="blue"><br />&nbsp;&nbsp; int</font></strong> c<strong><font color="#ff00ff">;<br />}</font></strong>st<strong><font color="#ff00ff">[</font></strong><font color="#cc3300">4</font><strong><font color="#ff00ff">*</font></strong>N<strong><font color="#ff00ff">];</font></strong><strong><font color="blue"><br />int</font></strong> q<strong><font color="#ff00ff">[</font></strong><font color="#cc3300">500000</font><strong><font color="#ff00ff">][</font></strong><font color="#cc3300">4</font><strong><font color="#ff00ff">],</font></strong>c<strong><font color="#ff00ff">;</font></strong><strong><font color="blue"><br />int</font></strong> remap<strong><font color="#ff00ff">[</font></strong>N<strong><font color="#ff00ff">],</font></strong>position<strong><font color="#ff00ff">[</font></strong>N<strong><font color="#ff00ff">];</font></strong><br />map<strong><font color="#ff00ff">&lt;</font></strong><strong><font color="blue">int</font></strong><strong><font color="#ff00ff">,</font></strong><strong><font color="blue">int</font></strong><strong><font color="#ff00ff">&gt;</font></strong> refer<strong><font color="#ff00ff">;</font></strong><strong><font color="blue"><br />void</font></strong> init<strong><font color="#ff00ff">(</font></strong><strong><font color="blue">int</font></strong> s<strong><font color="#ff00ff">,</font></strong><strong><font color="blue">int</font></strong> e<strong><font color="#ff00ff">,</font></strong><strong><font color="blue">int</font></strong> layer<strong><font color="#ff00ff">,</font></strong><strong><font color="blue">int</font></strong> pos<strong><font color="#ff00ff">=</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">)<br />{</font></strong><br />&nbsp;&nbsp;&nbsp; st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">=</font></strong>s<strong><font color="#ff00ff">;</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>e<strong><font color="#ff00ff">=</font></strong>e<strong><font color="#ff00ff">;</font></strong><br />&nbsp;&nbsp;&nbsp; st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">=</font></strong>layer<strong><font color="#ff00ff">;</font></strong><br />&nbsp;&nbsp;&nbsp; st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>c<strong><font color="#ff00ff">=</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">;</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp; if</font></strong><strong><font color="#ff00ff">(</font></strong>s<strong><font color="#ff00ff">!=</font></strong>e<strong><font color="#ff00ff">)</font></strong> init<strong><font color="#ff00ff">(</font></strong>s<strong><font color="#ff00ff">,(</font></strong>s<strong><font color="#ff00ff">+</font></strong>e<strong><font color="#ff00ff">)/</font></strong><font color="#cc3300">2</font><strong><font color="#ff00ff">,</font></strong>layer<strong><font color="#ff00ff">+</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">,</font></strong>pos<strong><font color="#ff00ff">&lt;&lt;</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">),</font></strong>init<strong><font color="#ff00ff">((</font></strong>s<strong><font color="#ff00ff">+</font></strong>e<strong><font color="#ff00ff">)/</font></strong><font color="#cc3300">2</font><strong><font color="#ff00ff">+</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">,</font></strong>e<strong><font color="#ff00ff">,</font></strong>layer<strong><font color="#ff00ff">+</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">,(</font></strong>pos<strong><font color="#ff00ff">&lt;&lt;</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">)+</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">);<br />}</font></strong><strong><font color="blue"><br />void</font></strong> insert<strong><font color="#ff00ff">(</font></strong><strong><font color="blue">int</font></strong> value<strong><font color="#ff00ff">,</font></strong><strong><font color="blue">int</font></strong> pos<strong><font color="#ff00ff">=</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">)<br />{</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp; if</font></strong><strong><font color="#ff00ff">(</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">==</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>e<strong><font color="#ff00ff">)</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>c<strong><font color="#ff00ff">++]=</font></strong>value<strong><font color="#ff00ff">;</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp; else</font></strong><strong><font color="#ff00ff"><br />&nbsp;&nbsp;&nbsp;&nbsp; {</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if</font></strong><strong><font color="#ff00ff">(</font></strong>value<strong><font color="#ff00ff">&lt;=(</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">+</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>e<strong><font color="#ff00ff">)/</font></strong><font color="#cc3300">2</font><strong><font color="#ff00ff">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>c<strong><font color="#ff00ff">]=(</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>c<strong><font color="#ff00ff">==</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">?</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">:</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>c<strong><font color="#ff00ff">-</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">])+</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">;</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>c<strong><font color="#ff00ff">++;</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insert<strong><font color="#ff00ff">(</font></strong>value<strong><font color="#ff00ff">,</font></strong>pos<strong><font color="#ff00ff">&lt;&lt;</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else</font></strong><strong><font color="#ff00ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>c<strong><font color="#ff00ff">]=(</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>c<strong><font color="#ff00ff">==</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">?</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">:</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>c<strong><font color="#ff00ff">-</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">]);</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>c<strong><font color="#ff00ff">++;</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insert<strong><font color="#ff00ff">(</font></strong>value<strong><font color="#ff00ff">,(</font></strong>pos<strong><font color="#ff00ff">&lt;&lt;</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">)+</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp; }<br />}</font></strong><strong><font color="blue"><br />int</font></strong> q1<strong><font color="#ff00ff">(</font></strong><strong><font color="blue">int</font></strong> s<strong><font color="#ff00ff">,</font></strong><strong><font color="blue">int</font></strong> t<strong><font color="#ff00ff">,</font></strong><strong><font color="blue">int</font></strong> k<strong><font color="#ff00ff">,</font></strong><strong><font color="blue">int</font></strong> pos<strong><font color="#ff00ff">=</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">)<br />{</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp; if</font></strong><strong><font color="#ff00ff">(</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">==</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>e<strong><font color="#ff00ff">)</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return</font></strong>&nbsp; remap<strong><font color="#ff00ff">[</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">]];</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp; else</font></strong><strong><font color="#ff00ff"><br />&nbsp;&nbsp;&nbsp; {</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if</font></strong><strong><font color="#ff00ff">(</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>t<strong><font color="#ff00ff">]-(</font></strong>s<strong><font color="#ff00ff">==</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">?</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">:</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>s<strong><font color="#ff00ff">-</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">])&gt;=</font></strong>k<strong><font color="#ff00ff">)</font></strong><font color="green">//left<br /></font><strong><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return</font></strong> q1<strong><font color="#ff00ff">(</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">+(</font></strong>s<strong><font color="#ff00ff">==</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">?</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">:</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>s<strong><font color="#ff00ff">-</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">]),</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">+</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>t<strong><font color="#ff00ff">]-</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">,</font></strong>k<strong><font color="#ff00ff">,</font></strong>pos<strong><font color="#ff00ff">&lt;&lt;</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">);</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else</font></strong><font color="green">//right<br /></font><strong><font color="#ff00ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; k<strong><font color="#ff00ff">-=</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>t<strong><font color="#ff00ff">]-(</font></strong>s<strong><font color="#ff00ff">==</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">?</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">:</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>s<strong><font color="#ff00ff">-</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">]);</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return</font></strong> q1<strong><font color="#ff00ff">((</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">+</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>e<strong><font color="#ff00ff">)/</font></strong><font color="#cc3300">2</font><strong><font color="#ff00ff">+</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">+</font></strong>s<strong><font color="#ff00ff">-</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">-</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">+</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">-(</font></strong>s<strong><font color="#ff00ff">==</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">?</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">:</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>s<strong><font color="#ff00ff">-</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">]),(</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">+</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>e<strong><font color="#ff00ff">)/</font></strong><font color="#cc3300">2</font><strong><font color="#ff00ff">+</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">+</font></strong>t<strong><font color="#ff00ff">-</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">+</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">-</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>t<strong><font color="#ff00ff">]-</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">,</font></strong>k<strong><font color="#ff00ff">,(</font></strong>pos<strong><font color="#ff00ff">&lt;&lt;</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">)+</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}</font></strong><strong><font color="blue"><br />int</font></strong> q2<strong><font color="#ff00ff">(</font></strong><strong><font color="blue">int</font></strong> s<strong><font color="#ff00ff">,</font></strong><strong><font color="blue">int</font></strong> pos<strong><font color="#ff00ff">=</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">)<br />{</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp; if</font></strong><strong><font color="#ff00ff">(</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">==</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>e<strong><font color="#ff00ff">)</font></strong><strong><font color="#0000ff"> return</font></strong><font color="#cc3300"> 1</font><strong><font color="#ff00ff">;</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp; else if</font></strong><strong><font color="#ff00ff">(</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>s<strong><font color="#ff00ff">]-(</font></strong>s<strong><font color="#ff00ff">==</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">?</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">:</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>s<strong><font color="#ff00ff">-</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">]))</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return</font></strong> q2<strong><font color="#ff00ff">(</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">+</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>s<strong><font color="#ff00ff">]-</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">,</font></strong>pos<strong><font color="#ff00ff">&lt;&lt;</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">);</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp; else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return</font></strong><strong><font color="#ff00ff"> (</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>c<strong><font color="#ff00ff">==</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">?</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">:</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>c<strong><font color="#ff00ff">-</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">])+</font></strong>q2<strong><font color="#ff00ff">((</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">+</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>e<strong><font color="#ff00ff">)/</font></strong><font color="#cc3300">2</font><strong><font color="#ff00ff">+</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">+</font></strong>s<strong><font color="#ff00ff">-</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">+</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">-</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>s<strong><font color="#ff00ff">]-</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">,(</font></strong>pos<strong><font color="#ff00ff">&lt;&lt;</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">)+</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">);<br />}</font></strong><strong><font color="blue"><br />int</font></strong> q3<strong><font color="#ff00ff">(</font></strong><strong><font color="blue">int</font></strong> k<strong><font color="#ff00ff">,</font></strong><strong><font color="blue">int</font></strong> pos<strong><font color="#ff00ff">=</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">)<br />{</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp; if</font></strong><strong><font color="#ff00ff">(</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">==</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>e<strong><font color="#ff00ff">)</font></strong><strong><font color="#0000ff"> return</font></strong> remap<strong><font color="#ff00ff">[</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">]];</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp; else if</font></strong><strong><font color="#ff00ff">(</font></strong>k<strong><font color="#ff00ff">&lt;=(</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>c<strong><font color="#ff00ff">==</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">?</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">:</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>c<strong><font color="#ff00ff">-</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">]))</font></strong><strong><font color="#0000ff"> return</font></strong> q3<strong><font color="#ff00ff">(</font></strong>k<strong><font color="#ff00ff">,</font></strong>pos<strong><font color="#ff00ff">&lt;&lt;</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">);</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp; else return</font></strong> q3<strong><font color="#ff00ff">(</font></strong>k<strong><font color="#ff00ff">-(</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>s<strong><font color="#ff00ff">==</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>c<strong><font color="#ff00ff">?</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">:</font></strong>arr<strong><font color="#ff00ff">[</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>layer<strong><font color="#ff00ff">][</font></strong>st<strong><font color="#ff00ff">[</font></strong>pos<strong><font color="#ff00ff">].</font></strong>c<strong><font color="#ff00ff">-</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">]),(</font></strong>pos<strong><font color="#ff00ff">&lt;&lt;</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">)+</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">);<br />}</font></strong><strong><font color="blue"><br />int</font></strong><strong><font color="#0000ff"> main</font></strong><strong><font color="#ff00ff">()<br />{</font></strong><strong><font color="blue"><br />&nbsp;&nbsp;&nbsp; int</font></strong> n<strong><font color="#ff00ff">,</font></strong>test<strong><font color="#ff00ff">=</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">;</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp; while</font></strong><strong><font color="#ff00ff">(</font></strong>scanf<strong><font color="#ff00ff">(</font></strong><font color="green">"%d"</font><strong><font color="#ff00ff">,&amp;</font></strong>n<strong><font color="#ff00ff">)!=</font></strong>EOF<strong><font color="#ff00ff">)<br />&nbsp;&nbsp;&nbsp; {</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; refer<strong><font color="#ff00ff">.</font></strong>clear<strong><font color="#ff00ff">();</font></strong>c<strong><font color="#ff00ff">=</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">;</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memset<strong><font color="#ff00ff">(</font></strong>arr<strong><font color="#ff00ff">,</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">,</font></strong><strong><font color="#0000ff">sizeof</font></strong><strong><font color="#ff00ff">(</font></strong>arr<strong><font color="#ff00ff">));</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for</font></strong><strong><font color="#ff00ff">(</font></strong><strong><font color="blue">int</font></strong> i<strong><font color="#ff00ff">=</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">;</font></strong>i<strong><font color="#ff00ff">&lt;</font></strong>n<strong><font color="#ff00ff">;</font></strong>i<strong><font color="#ff00ff">++)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</font></strong><strong><font color="blue"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char</font></strong> tmp<strong><font color="#ff00ff">[</font></strong><font color="#cc3300">12</font><strong><font color="#ff00ff">];</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scanf<strong><font color="#ff00ff">(</font></strong><font color="green">"%s"</font><strong><font color="#ff00ff">,</font></strong>tmp<strong><font color="#ff00ff">);</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if</font></strong><strong><font color="#ff00ff">(*</font></strong>tmp<strong><font color="#ff00ff">==</font></strong><font color="green">'I'</font><strong><font color="#ff00ff">)</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">]=</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">;</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else</font></strong> q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">]=</font></strong>tmp<strong><font color="#ff00ff">[</font></strong><font color="#cc3300">6</font><strong><font color="#ff00ff">]-</font></strong><font color="#cc3300">48</font><strong><font color="#ff00ff">;</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch</font></strong><strong><font color="#ff00ff">(</font></strong>q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">])<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case</font></strong><font color="#cc3300"> 0</font><strong><font color="#ff00ff">:</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scanf<strong><font color="#ff00ff">(</font></strong><font color="green">"%d"</font><strong><font color="#ff00ff">,&amp;</font></strong>q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">]);</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; refer<strong><font color="#ff00ff">[</font></strong>q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">]]=</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">;</font></strong><strong><font color="#0000ff"> <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break</font></strong><strong><font color="#ff00ff">;</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case</font></strong><font color="#cc3300"> 1</font><strong><font color="#ff00ff">:</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scanf<strong><font color="#ff00ff">(</font></strong><font color="green">"%d%d%d"</font><strong><font color="#ff00ff">,&amp;</font></strong>q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">],&amp;</font></strong>q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">2</font><strong><font color="#ff00ff">],&amp;</font></strong>q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">3</font><strong><font color="#ff00ff">]);</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break</font></strong><strong><font color="#ff00ff">;</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default</font></strong><strong><font color="#ff00ff">:</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scanf<strong><font color="#ff00ff">(</font></strong><font color="green">"%d"</font><strong><font color="#ff00ff">,&amp;</font></strong>q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">]);</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break</font></strong><strong><font color="#ff00ff">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for</font></strong><strong><font color="#ff00ff">(</font></strong>map<strong><font color="#ff00ff">&lt;</font></strong><strong><font color="blue">int</font></strong><strong><font color="#ff00ff">,</font></strong><strong><font color="blue">int</font></strong><strong><font color="#ff00ff">&gt;::</font></strong>iterator i<strong><font color="#ff00ff">=</font></strong>refer<strong><font color="#ff00ff">.</font></strong>begin<strong><font color="#ff00ff">();</font></strong>i<strong><font color="#ff00ff">!=</font></strong>refer<strong><font color="#ff00ff">.</font></strong>end<strong><font color="#ff00ff">();</font></strong>i<strong><font color="#ff00ff">++)</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; remap<strong><font color="#ff00ff">[</font></strong>c<strong><font color="#ff00ff">]=</font></strong>i<strong><font color="#ff00ff">-&gt;</font></strong>first<strong><font color="#ff00ff">,</font></strong>i<strong><font color="#ff00ff">-&gt;</font></strong>second<strong><font color="#ff00ff">=</font></strong>c<strong><font color="#ff00ff">++;</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; init<strong><font color="#ff00ff">(</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">,</font></strong>c<strong><font color="#ff00ff">-</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">,</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">);</font></strong><strong><font color="blue"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long long</font></strong> t<strong><font color="#ff00ff">[</font></strong><font color="#cc3300">4</font><strong><font color="#ff00ff">]={</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">,</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">,</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">,</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">};</font></strong><strong><font color="blue"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int</font></strong> now<strong><font color="#ff00ff">=</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">;</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for</font></strong><strong><font color="#ff00ff">(</font></strong><strong><font color="blue">int</font></strong> i<strong><font color="#ff00ff">=</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">;</font></strong>i<strong><font color="#ff00ff">&lt;</font></strong>n<strong><font color="#ff00ff">;</font></strong>i<strong><font color="#ff00ff">++)</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch</font></strong><strong><font color="#ff00ff">(</font></strong>q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">0</font><strong><font color="#ff00ff">])<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case</font></strong><font color="#cc3300"> 0</font><strong><font color="#ff00ff">:</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insert<strong><font color="#ff00ff">(</font></strong>refer<strong><font color="#ff00ff">[</font></strong>q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">]]);</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; position<strong><font color="#ff00ff">[</font></strong>refer<strong><font color="#ff00ff">[</font></strong>q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">]]]=</font></strong>now<strong><font color="#ff00ff">++;</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break</font></strong><strong><font color="#ff00ff">;</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case</font></strong><font color="#cc3300"> 1</font><strong><font color="#ff00ff">:</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t<strong><font color="#ff00ff">[</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">]+=</font></strong>q1<strong><font color="#ff00ff">(</font></strong>q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">],</font></strong>q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">2</font><strong><font color="#ff00ff">],</font></strong>q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">3</font><strong><font color="#ff00ff">]);</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break</font></strong><strong><font color="#ff00ff">;</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case</font></strong><font color="#cc3300"> 2</font><strong><font color="#ff00ff">:</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t<strong><font color="#ff00ff">[</font></strong><font color="#cc3300">2</font><strong><font color="#ff00ff">]+=</font></strong>q2<strong><font color="#ff00ff">(</font></strong>position<strong><font color="#ff00ff">[</font></strong>refer<strong><font color="#ff00ff">[</font></strong>q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">]]]);</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break</font></strong><strong><font color="#ff00ff">;</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case</font></strong><font color="#cc3300"> 3</font><strong><font color="#ff00ff">:</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t<strong><font color="#ff00ff">[</font></strong><font color="#cc3300">3</font><strong><font color="#ff00ff">]+=</font></strong>q3<strong><font color="#ff00ff">(</font></strong>q<strong><font color="#ff00ff">[</font></strong>i<strong><font color="#ff00ff">][</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">]);</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break</font></strong><strong><font color="#ff00ff">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };</font></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf<strong><font color="#ff00ff">(</font></strong><font color="green">"Case %d:\n%I64d\n%I64d\n%I64d\n"</font><strong><font color="#ff00ff">,</font></strong>test<strong><font color="#ff00ff">++,</font></strong>t<strong><font color="#ff00ff">[</font></strong><font color="#cc3300">1</font><strong><font color="#ff00ff">],</font></strong>t<strong><font color="#ff00ff">[</font></strong><font color="#cc3300">2</font><strong><font color="#ff00ff">],</font></strong>t<strong><font color="#ff00ff">[</font></strong><font color="#cc3300">3</font><strong><font color="#ff00ff">]);<br />&nbsp;&nbsp;&nbsp; }</font></strong><strong><font color="#0000ff"><br />&nbsp;&nbsp;&nbsp; return</font></strong><font color="#cc3300"> 0</font><strong><font color="#ff00ff">;<br />}</font></strong><br /><img src ="http://www.cppblog.com/yzhw/aggbug/157189.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-09-30 08:44 <a href="http://www.cppblog.com/yzhw/archive/2011/09/30/157189.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku 3225 区间 我对线段树延迟标记的一些理解</title><link>http://www.cppblog.com/yzhw/archive/2011/09/09/155413.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Fri, 09 Sep 2011 01:31:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/09/09/155413.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/155413.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/09/09/155413.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/155413.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/155413.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 这题网上结题报告应该很多了，我也不想多写什么，但是写完这题后，我对延迟标记的更新策略有了更新的理解这题节点的结构应该算复杂的了Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1&nbsp;struct&nbsp;tree...&nbsp;&nbsp;<a href='http://www.cppblog.com/yzhw/archive/2011/09/09/155413.html'>阅读全文</a><img src ="http://www.cppblog.com/yzhw/aggbug/155413.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-09-09 09:31 <a href="http://www.cppblog.com/yzhw/archive/2011/09/09/155413.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku1916 Rat Attack 动态统计之经典好题</title><link>http://www.cppblog.com/yzhw/archive/2011/04/04/143419.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Mon, 04 Apr 2011 14:32:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/04/04/143419.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/143419.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/04/04/143419.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/143419.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/143419.html</trackback:ping><description><![CDATA[<p>题意<br><img border=0 alt="" src="http://poj.org/images/1916_1.jpg" width=576 height=338><br>在管道的焦点处有N个种群数目为Pi的鼠群，N&lt;20000，现在要在某个焦点处放一个炸弹，炸弹效力范围是以炸弹为中点的2d*2d的矩形。问炸弹放在哪里可以炸死最多的老鼠，如果有重复则优先保证X坐标最小，如果还有重复就Y坐标最小。<br>解法<br>这种题目一般是采用X扫描线+平衡树/树状数组统计的方法。但是这题由于还有第二和第三优先级，我们必须扫描线移动一下就统计一下，不能等到扫描线距离达到2d再统计，然后小x坐标就是后扫描线坐标减去d。用平衡树/树状数组统计时也要注意这个问题。详细情况见代码（我依然很猥琐的用了STL MAP）<br>PS，好不容易一题在poj rank进前3，不容易啊。。<br><span style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: medium Simsun; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class=Apple-style-span></p>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstdio</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">map</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">algorithm</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></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: #008080">&nbsp;5</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;node<br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img id=Codehighlighter1_90_169_Open_Image onclick="this.style.display='none'; Codehighlighter1_90_169_Open_Text.style.display='none'; Codehighlighter1_90_169_Closed_Image.style.display='inline'; Codehighlighter1_90_169_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_90_169_Closed_Image onclick="this.style.display='none'; Codehighlighter1_90_169_Closed_Text.style.display='none'; Codehighlighter1_90_169_Open_Image.style.display='inline'; Codehighlighter1_90_169_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_90_169_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_90_169_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x,y,num;<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;node&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">pos)&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img id=Codehighlighter1_146_167_Open_Image onclick="this.style.display='none'; Codehighlighter1_146_167_Open_Text.style.display='none'; Codehighlighter1_146_167_Closed_Image.style.display='inline'; Codehighlighter1_146_167_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_146_167_Closed_Image onclick="this.style.display='none'; Codehighlighter1_146_167_Closed_Text.style.display='none'; Codehighlighter1_146_167_Open_Image.style.display='inline'; Codehighlighter1_146_167_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_146_167_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_146_167_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;x</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">pos.x;<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">data[</span><span style="COLOR: #000000">20005</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;d,n;<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">map</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;refer;<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;calbest(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;nx,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">best,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">x,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">y)<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img id=Codehighlighter1_257_604_Open_Image onclick="this.style.display='none'; Codehighlighter1_257_604_Open_Text.style.display='none'; Codehighlighter1_257_604_Closed_Image.style.display='inline'; Codehighlighter1_257_604_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_257_604_Closed_Image onclick="this.style.display='none'; Codehighlighter1_257_604_Closed_Text.style.display='none'; Codehighlighter1_257_604_Open_Image.style.display='inline'; Codehighlighter1_257_604_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_257_604_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_257_604_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;map</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">::iterator&nbsp;s</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">refer.begin(),e</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">refer.begin();<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;total</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,last</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">e</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">first;<br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(e</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">refer.end())<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img id=Codehighlighter1_368_602_Open_Image onclick="this.style.display='none'; Codehighlighter1_368_602_Open_Text.style.display='none'; Codehighlighter1_368_602_Closed_Image.style.display='inline'; Codehighlighter1_368_602_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_368_602_Closed_Image onclick="this.style.display='none'; Codehighlighter1_368_602_Closed_Text.style.display='none'; Codehighlighter1_368_602_Open_Image.style.display='inline'; Codehighlighter1_368_602_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_368_602_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_368_602_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(e</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">refer.end()</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">e</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">first</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">s</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">first</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">d)<br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img id=Codehighlighter1_420_471_Open_Image onclick="this.style.display='none'; Codehighlighter1_420_471_Open_Text.style.display='none'; Codehighlighter1_420_471_Closed_Image.style.display='inline'; Codehighlighter1_420_471_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_420_471_Closed_Image onclick="this.style.display='none'; Codehighlighter1_420_471_Closed_Text.style.display='none'; Codehighlighter1_420_471_Open_Image.style.display='inline'; Codehighlighter1_420_471_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_420_471_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_420_471_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;total</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">e</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">second;<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;last</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">e</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">first;<br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(total</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">best</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">total</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">best</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">nx</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">d</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">total</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">best</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">nx</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">d</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">last</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">d</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">y)<br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;best</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">total,x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">nx</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">d,y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">last</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">d;<br></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;total</span><span style="COLOR: #000000">-=</span><span style="COLOR: #000000">s</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">second;<br></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">32</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">33</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img id=Codehighlighter1_617_1345_Open_Image onclick="this.style.display='none'; Codehighlighter1_617_1345_Open_Text.style.display='none'; Codehighlighter1_617_1345_Closed_Image.style.display='inline'; Codehighlighter1_617_1345_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_617_1345_Closed_Image onclick="this.style.display='none'; Codehighlighter1_617_1345_Closed_Text.style.display='none'; Codehighlighter1_617_1345_Open_Image.style.display='inline'; Codehighlighter1_617_1345_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_617_1345_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_617_1345_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">35</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">freopen("ans.txt","w",stdout);</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">36</span><span style="COLOR: #008000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;test;<br></span><span style="COLOR: #008080">37</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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">test);<br></span><span style="COLOR: #008080">38</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(test</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">39</span><span style="COLOR: #000000"><img id=Codehighlighter1_700_1332_Open_Image onclick="this.style.display='none'; Codehighlighter1_700_1332_Open_Text.style.display='none'; Codehighlighter1_700_1332_Closed_Image.style.display='inline'; Codehighlighter1_700_1332_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_700_1332_Closed_Image onclick="this.style.display='none'; Codehighlighter1_700_1332_Closed_Text.style.display='none'; Codehighlighter1_700_1332_Open_Image.style.display='inline'; Codehighlighter1_700_1332_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_700_1332_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_700_1332_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">40</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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">d,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">n);<br></span><span style="COLOR: #008080">41</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&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">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">42</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d%d%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">data[i].x,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">data[i].y,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">data[i].num);<br></span><span style="COLOR: #008080">43</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort(data,data</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">n);<br></span><span style="COLOR: #008080">44</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;s</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,e</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">45</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;refer.clear();<br></span><span style="COLOR: #008080">46</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;best</span><span style="COLOR: #000000">=-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,y,x;<br></span><span style="COLOR: #008080">47</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(e</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">n)<br></span><span style="COLOR: #008080">48</span><span style="COLOR: #000000"><img id=Codehighlighter1_890_1278_Open_Image onclick="this.style.display='none'; Codehighlighter1_890_1278_Open_Text.style.display='none'; Codehighlighter1_890_1278_Closed_Image.style.display='inline'; Codehighlighter1_890_1278_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_890_1278_Closed_Image onclick="this.style.display='none'; Codehighlighter1_890_1278_Closed_Text.style.display='none'; Codehighlighter1_890_1278_Open_Image.style.display='inline'; Codehighlighter1_890_1278_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_890_1278_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_890_1278_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">49</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;tmp;<br></span><span style="COLOR: #008080">50</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">51</span><span style="COLOR: #000000"><img id=Codehighlighter1_922_1120_Open_Image onclick="this.style.display='none'; Codehighlighter1_922_1120_Open_Text.style.display='none'; Codehighlighter1_922_1120_Closed_Image.style.display='inline'; Codehighlighter1_922_1120_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_922_1120_Closed_Image onclick="this.style.display='none'; Codehighlighter1_922_1120_Closed_Text.style.display='none'; Codehighlighter1_922_1120_Open_Image.style.display='inline'; Codehighlighter1_922_1120_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_922_1120_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_922_1120_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">52</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(e</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">data[e].x</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">data[s].x</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">d)&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">53</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">data[e].x;<br></span><span style="COLOR: #008080">54</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(e</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">data[e].x</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">tmp)&nbsp;<br></span><span style="COLOR: #008080">55</span><span style="COLOR: #000000"><img id=Codehighlighter1_1025_1080_Open_Image onclick="this.style.display='none'; Codehighlighter1_1025_1080_Open_Text.style.display='none'; Codehighlighter1_1025_1080_Closed_Image.style.display='inline'; Codehighlighter1_1025_1080_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1025_1080_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1025_1080_Closed_Text.style.display='none'; Codehighlighter1_1025_1080_Open_Image.style.display='inline'; Codehighlighter1_1025_1080_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1025_1080_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1025_1080_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">56</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;refer[data[e].y]</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">data[e].num;<br></span><span style="COLOR: #008080">57</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">58</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">59</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;calbest(data[e</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">].x,best,x,y);<br></span><span style="COLOR: #008080">60</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">61</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">data[s].x;<br></span><span style="COLOR: #008080">62</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(data[s].x</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">tmp</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">s</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">n)<br></span><span style="COLOR: #008080">63</span><span style="COLOR: #000000"><img id=Codehighlighter1_1173_1274_Open_Image onclick="this.style.display='none'; Codehighlighter1_1173_1274_Open_Text.style.display='none'; Codehighlighter1_1173_1274_Closed_Image.style.display='inline'; Codehighlighter1_1173_1274_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1173_1274_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1173_1274_Closed_Text.style.display='none'; Codehighlighter1_1173_1274_Open_Image.style.display='inline'; Codehighlighter1_1173_1274_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1173_1274_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1173_1274_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">64</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;refer[data[s].y]</span><span style="COLOR: #000000">-=</span><span style="COLOR: #000000">data[s].num;<br></span><span style="COLOR: #008080">65</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(refer[data[s].y]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;refer.erase(data[s].y);<br></span><span style="COLOR: #008080">66</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">67</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">68</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">69</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d&nbsp;%d&nbsp;%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,x</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">x:</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,y</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">y:</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,best);<br></span><span style="COLOR: #008080">70</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">71</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">72</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">73</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">74</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br></span><span style="COLOR: #008080">75</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
</span>
<img src ="http://www.cppblog.com/yzhw/aggbug/143419.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-04-04 22:32 <a href="http://www.cppblog.com/yzhw/archive/2011/04/04/143419.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku3168 Barn Expansion 排序+区间重叠判断</title><link>http://www.cppblog.com/yzhw/archive/2011/03/02/140951.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Tue, 01 Mar 2011 18:10:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/03/02/140951.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/140951.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/03/02/140951.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/140951.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/140951.html</trackback:ping><description><![CDATA[MS好久不写blog了，现在好忙，又是GRE，又是考研，又是ACM。。蛋疼<br>言归正传<br>题意:<br>给出一些长方形，不重叠，但可以擦边或擦角。问有多少个长方形是完全不和别的长方形沾边的<br><br>给力条件：不重叠<br><br>方法：经典的排序+区间合并<br><br>代码：<br><div style="background-color: rgb(238, 238, 238); font-size: 13px; border-left-color: rgb(204, 204, 204); padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; "><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080; ">&nbsp;1</span>&nbsp;<span style="color: #000000; ">#&nbsp;include&nbsp;</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">cstdio</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br></span><span style="color: #008080; ">&nbsp;2</span>&nbsp;<span style="color: #000000; ">#&nbsp;include&nbsp;</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">cstring</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br></span><span style="color: #008080; ">&nbsp;3</span>&nbsp;<span style="color: #000000; ">#&nbsp;include&nbsp;</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">cstdlib</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br></span><span style="color: #008080; ">&nbsp;4</span>&nbsp;<span style="color: #000000; ">#&nbsp;define&nbsp;max(a,b)&nbsp;((a)</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; ">(b)</span><span style="color: #000000; ">?</span><span style="color: #000000; ">(a):(b))<br></span><span style="color: #008080; ">&nbsp;5</span>&nbsp;<span style="color: #000000; "></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: #008080; ">&nbsp;6</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">struct</span><span style="color: #000000; ">&nbsp;line<br></span><span style="color: #008080; ">&nbsp;7</span>&nbsp;<span style="color: #000000; ">{<br></span><span style="color: #008080; ">&nbsp;8</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;s,e,p,id;<br></span><span style="color: #008080; ">&nbsp;9</span>&nbsp;<span style="color: #000000; ">}tmp[</span><span style="color: #000000; ">60000</span><span style="color: #000000; ">];<br></span><span style="color: #008080; ">10</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;cmp(</span><span style="color: #0000FF; ">const</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">a,</span><span style="color: #0000FF; ">const</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">b)<br></span><span style="color: #008080; ">11</span>&nbsp;<span style="color: #000000; ">{<br></span><span style="color: #008080; ">12</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;line&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">aa</span><span style="color: #000000; ">=</span><span style="color: #000000; ">(line&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">)a,</span><span style="color: #000000; ">*</span><span style="color: #000000; ">bb</span><span style="color: #000000; ">=</span><span style="color: #000000; ">(line&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">)b;<br></span><span style="color: #008080; ">13</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(aa</span><span style="color: #000000; ">-&gt;</span><span style="color: #000000; ">p</span><span style="color: #000000; ">!=</span><span style="color: #000000; ">bb</span><span style="color: #000000; ">-&gt;</span><span style="color: #000000; ">p)&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">&nbsp;aa</span><span style="color: #000000; ">-&gt;</span><span style="color: #000000; ">p</span><span style="color: #000000; ">-</span><span style="color: #000000; ">bb</span><span style="color: #000000; ">-&gt;</span><span style="color: #000000; ">p;<br></span><span style="color: #008080; ">14</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">else</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">&nbsp;aa</span><span style="color: #000000; ">-&gt;</span><span style="color: #000000; ">s</span><span style="color: #000000; ">-</span><span style="color: #000000; ">bb</span><span style="color: #000000; ">-&gt;</span><span style="color: #000000; ">s;<br></span><span style="color: #008080; ">15</span>&nbsp;<span style="color: #000000; ">}<br></span><span style="color: #008080; ">16</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;data[</span><span style="color: #000000; ">30000</span><span style="color: #000000; ">][</span><span style="color: #000000; ">4</span><span style="color: #000000; ">],n;<br></span><span style="color: #008080; ">17</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">bool</span><span style="color: #000000; ">&nbsp;used[</span><span style="color: #000000; ">30000</span><span style="color: #000000; ">];<br></span><span style="color: #008080; ">18</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;solve()<br></span><span style="color: #008080; ">19</span>&nbsp;<span style="color: #000000; ">{<br></span><span style="color: #008080; ">20</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;end</span><span style="color: #000000; ">=</span><span style="color: #000000; ">tmp[</span><span style="color: #000000; ">0</span><span style="color: #000000; ">].e,last</span><span style="color: #000000; ">=</span><span style="color: #000000; ">0</span><span style="color: #000000; ">;<br></span><span style="color: #008080; ">21</span>&nbsp;<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; ">1</span><span style="color: #000000; ">;i</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">n;i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">22</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(tmp[i].p</span><span style="color: #000000; ">==</span><span style="color: #000000; ">tmp[i</span><span style="color: #000000; ">-</span><span style="color: #000000; ">1</span><span style="color: #000000; ">].p</span><span style="color: #000000; ">&amp;&amp;</span><span style="color: #000000; ">tmp[i].s</span><span style="color: #000000; ">&lt;=</span><span style="color: #000000; ">end)<br></span><span style="color: #008080; ">23</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end</span><span style="color: #000000; ">=</span><span style="color: #000000; ">max(end,tmp[i].e);<br></span><span style="color: #008080; ">24</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">else</span><span style="color: #000000; "><br></span><span style="color: #008080; ">25</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080; ">26</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(last</span><span style="color: #000000; ">!=</span><span style="color: #000000; ">i</span><span style="color: #000000; ">-</span><span style="color: #000000; ">1</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">27</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;j</span><span style="color: #000000; ">=</span><span style="color: #000000; ">last;j</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">i;j</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">28</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;used[tmp[j].id]</span><span style="color: #000000; ">=</span><span style="color: #0000FF; ">false</span><span style="color: #000000; ">;<br></span><span style="color: #008080; ">29</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end</span><span style="color: #000000; ">=</span><span style="color: #000000; ">tmp[i].e;<br></span><span style="color: #008080; ">30</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;last</span><span style="color: #000000; ">=</span><span style="color: #000000; ">i;<br></span><span style="color: #008080; ">31</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080; ">32</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(last</span><span style="color: #000000; ">!=</span><span style="color: #000000; ">2</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; ">)<br></span><span style="color: #008080; ">33</span>&nbsp;<span style="color: #000000; ">&nbsp;&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;j</span><span style="color: #000000; ">=</span><span style="color: #000000; ">last;j</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">n;j</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">34</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;used[tmp[j].id]</span><span style="color: #000000; ">=</span><span style="color: #0000FF; ">false</span><span style="color: #000000; ">;<br></span><span style="color: #008080; ">35</span>&nbsp;<span style="color: #000000; ">}<br></span><span style="color: #008080; ">36</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;main()<br></span><span style="color: #008080; ">37</span>&nbsp;<span style="color: #000000; ">{<br></span><span style="color: #008080; ">38</span>&nbsp;<span style="color: #000000; ">&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></span><span style="color: #008080; ">39</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;memset(used,</span><span style="color: #0000FF; ">true</span><span style="color: #000000; ">,</span><span style="color: #0000FF; ">sizeof</span><span style="color: #000000; ">(used));<br></span><span style="color: #008080; ">40</span>&nbsp;<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; ">n;i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">41</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">%d%d%d%d</span><span style="color: #000000; ">"</span><span style="color: #000000; ">,</span><span style="color: #000000; ">&amp;</span><span style="color: #000000; ">data[i][</span><span style="color: #000000; ">0</span><span style="color: #000000; ">],</span><span style="color: #000000; ">&amp;</span><span style="color: #000000; ">data[i][</span><span style="color: #000000; ">1</span><span style="color: #000000; ">],</span><span style="color: #000000; ">&amp;</span><span style="color: #000000; ">data[i][</span><span style="color: #000000; ">2</span><span style="color: #000000; ">],</span><span style="color: #000000; ">&amp;</span><span style="color: #000000; ">data[i][</span><span style="color: #000000; ">3</span><span style="color: #000000; ">]);<br></span><span style="color: #008080; ">42</span>&nbsp;<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; ">n;i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">43</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080; ">44</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">i].s</span><span style="color: #000000; ">=</span><span style="color: #000000; ">data[i][</span><span style="color: #000000; ">0</span><span style="color: #000000; ">];<br></span><span style="color: #008080; ">45</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">i].e</span><span style="color: #000000; ">=</span><span style="color: #000000; ">data[i][</span><span style="color: #000000; ">2</span><span style="color: #000000; ">];<br></span><span style="color: #008080; ">46</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">i].p</span><span style="color: #000000; ">=</span><span style="color: #000000; ">data[i][</span><span style="color: #000000; ">1</span><span style="color: #000000; ">];<br></span><span style="color: #008080; ">47</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">i].id</span><span style="color: #000000; ">=</span><span style="color: #000000; ">i;<br></span><span style="color: #008080; ">48</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">i</span><span style="color: #000000; ">+</span><span style="color: #000000; ">1</span><span style="color: #000000; ">]</span><span style="color: #000000; ">=</span><span style="color: #000000; ">tmp[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">i];<br></span><span style="color: #008080; ">49</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">i</span><span style="color: #000000; ">+</span><span style="color: #000000; ">1</span><span style="color: #000000; ">].p</span><span style="color: #000000; ">=</span><span style="color: #000000; ">data[i][</span><span style="color: #000000; ">3</span><span style="color: #000000; ">];<br></span><span style="color: #008080; ">50</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080; ">51</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;qsort(tmp,</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">n,</span><span style="color: #0000FF; ">sizeof</span><span style="color: #000000; ">(line),cmp);<br></span><span style="color: #008080; ">52</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">/*</span><span style="color: #008000; ">&nbsp;printf("\n");<br></span><span style="color: #008080; ">53</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;i=0;i&lt;2*n;i++)<br></span><span style="color: #008080; ">54</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("%d&nbsp;%d&nbsp;%d&nbsp;%d\n",tmp[i].id,tmp[i].p,tmp[i].s,tmp[i].e);<br></span><span style="color: #008080; ">55</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;printf("\n");</span><span style="color: #008000; ">*/</span><span style="color: #000000; "><br></span><span style="color: #008080; ">56</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;solve();<br></span><span style="color: #008080; ">57</span>&nbsp;<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; ">n;i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">58</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080; ">59</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">i].s</span><span style="color: #000000; ">=</span><span style="color: #000000; ">data[i][</span><span style="color: #000000; ">1</span><span style="color: #000000; ">];<br></span><span style="color: #008080; ">60</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">i].e</span><span style="color: #000000; ">=</span><span style="color: #000000; ">data[i][</span><span style="color: #000000; ">3</span><span style="color: #000000; ">];<br></span><span style="color: #008080; ">61</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">i].p</span><span style="color: #000000; ">=</span><span style="color: #000000; ">data[i][</span><span style="color: #000000; ">0</span><span style="color: #000000; ">];<br></span><span style="color: #008080; ">62</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">i].id</span><span style="color: #000000; ">=</span><span style="color: #000000; ">i;<br></span><span style="color: #008080; ">63</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">i</span><span style="color: #000000; ">+</span><span style="color: #000000; ">1</span><span style="color: #000000; ">]</span><span style="color: #000000; ">=</span><span style="color: #000000; ">tmp[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">i];<br></span><span style="color: #008080; ">64</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">i</span><span style="color: #000000; ">+</span><span style="color: #000000; ">1</span><span style="color: #000000; ">].p</span><span style="color: #000000; ">=</span><span style="color: #000000; ">data[i][</span><span style="color: #000000; ">2</span><span style="color: #000000; ">];<br></span><span style="color: #008080; ">65</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080; ">66</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;qsort(tmp,</span><span style="color: #000000; ">2</span><span style="color: #000000; ">*</span><span style="color: #000000; ">n,</span><span style="color: #0000FF; ">sizeof</span><span style="color: #000000; ">(line),cmp);<br></span><span style="color: #008080; ">67</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">/*</span><span style="color: #008000; ">&nbsp;for(int&nbsp;i=0;i&lt;2*n;i++)<br></span><span style="color: #008080; ">68</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("%d&nbsp;%d&nbsp;%d&nbsp;%d\n",tmp[i].id,tmp[i].p,tmp[i].s,tmp[i].e);<br></span><span style="color: #008080; ">69</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;printf("\n");</span><span style="color: #008000; ">*/</span><span style="color: #000000; "><br></span><span style="color: #008080; ">70</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;solve();<br></span><span style="color: #008080; ">71</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;c</span><span style="color: #000000; ">=</span><span style="color: #000000; ">0</span><span style="color: #000000; ">;<br></span><span style="color: #008080; ">72</span>&nbsp;<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; ">n;i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">73</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="color: #000000; ">+=</span><span style="color: #000000; ">used[i];<br></span><span style="color: #008080; ">74</span>&nbsp;<span style="color: #000000; ">&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; ">,c);<br></span><span style="color: #008080; ">75</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">system("pause");</span><span style="color: #008000; "><br></span><span style="color: #008080; ">76</span>&nbsp;<span style="color: #008000; "></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">0</span><span style="color: #000000; ">;<br></span><span style="color: #008080; ">77</span>&nbsp;<span style="color: #000000; ">}<br></span><span style="color: #008080; ">78</span>&nbsp;<span style="color: #000000; "></span></div><img src ="http://www.cppblog.com/yzhw/aggbug/140951.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-03-02 02:10 <a href="http://www.cppblog.com/yzhw/archive/2011/03/02/140951.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku1944 Fiber Communications 图论好题！总体上的观察，算法不难</title><link>http://www.cppblog.com/yzhw/archive/2011/02/05/139737.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Fri, 04 Feb 2011 17:20:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/02/05/139737.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/139737.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/02/05/139737.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/139737.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/139737.html</trackback:ping><description><![CDATA[题意：<br>n个节点组成一个环，相邻节点间可以连边，有m对点间需要通讯，问最少要构造多少通讯线路<br><br>解答：<br>首先，要明确一点，a,b之间要通讯，只能有两种通讯线路[1,a),[a,n)，还有一个重要条件就是最多只需要构建n-1条边能将所有点联通。这样就只要枚举断电点，所有对通讯节点中的连接方式就都确定了，因为连接路径是互补的。断开一个点，一条路径就被砍断了，只能选择另外一条。然后统计覆盖的点的时候建议使用树状数组，树状数组表示这种左开右闭的区间是很给力的。左端点+1，右端点-1，复杂度n2logn。<br><br>代码&nbsp;<br><div style="background-color: rgb(238, 238, 238); font-size: 13px; border-left-color: rgb(204, 204, 204); padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; "><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080; ">&nbsp;1</span>&nbsp;<span style="color: #000000; ">#&nbsp;include&nbsp;</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">cstdio</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br></span><span style="color: #008080; ">&nbsp;2</span>&nbsp;<span style="color: #000000; ">#&nbsp;include&nbsp;</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">utility</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br></span><span style="color: #008080; ">&nbsp;3</span>&nbsp;<span style="color: #000000; ">#&nbsp;include&nbsp;</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">functional</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br></span><span style="color: #008080; ">&nbsp;4</span>&nbsp;<span style="color: #000000; ">#&nbsp;include&nbsp;</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: #008080; ">&nbsp;5</span>&nbsp;<span style="color: #000000; ">#&nbsp;include&nbsp;</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">algorithm</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br></span><span style="color: #008080; ">&nbsp;6</span>&nbsp;<span style="color: #000000; ">#&nbsp;include&nbsp;</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">cstring</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br></span><span style="color: #008080; ">&nbsp;7</span>&nbsp;<span style="color: #000000; ">#&nbsp;define&nbsp;lowbit(a)&nbsp;(a</span><span style="color: #000000; ">&amp;-</span><span style="color: #000000; ">a)<br></span><span style="color: #008080; ">&nbsp;8</span>&nbsp;<span style="color: #000000; "></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: #008080; ">&nbsp;9</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;arr[</span><span style="color: #000000; ">1005</span><span style="color: #000000; ">],n,m;<br></span><span style="color: #008080; ">10</span>&nbsp;<span style="color: #000000; ">pair</span><span style="color: #000000; ">&lt;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">,</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; ">data[</span><span style="color: #000000; ">10005</span><span style="color: #000000; ">];<br></span><span style="color: #008080; ">11</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;add(</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;p,</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;num)<br></span><span style="color: #008080; ">12</span>&nbsp;<span style="color: #000000; ">{<br></span><span style="color: #008080; ">13</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">while</span><span style="color: #000000; ">(p</span><span style="color: #000000; ">&lt;=</span><span style="color: #000000; ">n)&nbsp;<br></span><span style="color: #008080; ">14</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;arr[p]</span><span style="color: #000000; ">+=</span><span style="color: #000000; ">num,p</span><span style="color: #000000; ">+=</span><span style="color: #000000; ">lowbit(p);<br></span><span style="color: #008080; ">15</span>&nbsp;<span style="color: #000000; ">}<br></span><span style="color: #008080; ">16</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;sum(</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;p)<br></span><span style="color: #008080; ">17</span>&nbsp;<span style="color: #000000; ">{<br></span><span style="color: #008080; ">18</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;res</span><span style="color: #000000; ">=</span><span style="color: #000000; ">0</span><span style="color: #000000; ">;<br></span><span style="color: #008080; ">19</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">while</span><span style="color: #000000; ">(p</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; ">0</span><span style="color: #000000; ">)&nbsp;<br></span><span style="color: #008080; ">20</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res</span><span style="color: #000000; ">+=</span><span style="color: #000000; ">arr[p],p</span><span style="color: #000000; ">-=</span><span style="color: #000000; ">lowbit(p);<br></span><span style="color: #008080; ">21</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">&nbsp;res;<br></span><span style="color: #008080; ">22</span>&nbsp;<span style="color: #000000; ">}<br></span><span style="color: #008080; ">23</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;main()<br></span><span style="color: #008080; ">24</span>&nbsp;<span style="color: #000000; ">{<br></span><span style="color: #008080; ">25</span>&nbsp;<span style="color: #000000; ">&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; ">n,</span><span style="color: #000000; ">&amp;</span><span style="color: #000000; ">m);<br></span><span style="color: #008080; ">26</span>&nbsp;<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; ">m;i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">27</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080; ">28</span>&nbsp;<span style="color: #000000; ">&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; ">data[i].first,</span><span style="color: #000000; ">&amp;</span><span style="color: #000000; ">data[i].second);<br></span><span style="color: #008080; ">29</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(data[i].first</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; ">data[i].second)<br></span><span style="color: #008080; ">30</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;swap(data[i].first,data[i].second);<br></span><span style="color: #008080; ">31</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080; ">32</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;ans</span><span style="color: #000000; ">=</span><span style="color: #000000; ">0xfffffff</span><span style="color: #000000; ">;<br></span><span style="color: #008080; ">33</span>&nbsp;<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; ">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></span><span style="color: #008080; ">34</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080; ">35</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(arr,</span><span style="color: #000000; ">0</span><span style="color: #000000; ">,</span><span style="color: #0000FF; ">sizeof</span><span style="color: #000000; ">(arr));<br></span><span style="color: #008080; ">36</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&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;j</span><span style="color: #000000; ">=</span><span style="color: #000000; ">0</span><span style="color: #000000; ">;j</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">m;j</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">37</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(data[j].first</span><span style="color: #000000; ">&lt;=</span><span style="color: #000000; ">i</span><span style="color: #000000; ">&amp;&amp;</span><span style="color: #000000; ">data[j].second</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; ">i)<br></span><span style="color: #008080; ">38</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add(</span><span style="color: #000000; ">1</span><span style="color: #000000; ">,</span><span style="color: #000000; ">1</span><span style="color: #000000; ">),add(data[j].first,</span><span style="color: #000000; ">-</span><span style="color: #000000; ">1</span><span style="color: #000000; ">),add(data[j].second,</span><span style="color: #000000; ">1</span><span style="color: #000000; ">);<br></span><span style="color: #008080; ">39</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">else</span><span style="color: #000000; "><br></span><span style="color: #008080; ">40</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add(data[j].first,</span><span style="color: #000000; ">1</span><span style="color: #000000; ">),add(data[j].second,</span><span style="color: #000000; ">-</span><span style="color: #000000; ">1</span><span style="color: #000000; ">);<br></span><span style="color: #008080; ">41</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;res</span><span style="color: #000000; ">=</span><span style="color: #000000; ">0</span><span style="color: #000000; ">;<br></span><span style="color: #008080; ">42</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&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;j</span><span style="color: #000000; ">=</span><span style="color: #000000; ">1</span><span style="color: #000000; ">;j</span><span style="color: #000000; ">&lt;=</span><span style="color: #000000; ">n;j</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">43</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(sum(j)</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; ">0</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">44</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res</span><span style="color: #000000; ">++</span><span style="color: #000000; ">;<br></span><span style="color: #008080; ">45</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(res</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">ans)&nbsp;ans</span><span style="color: #000000; ">=</span><span style="color: #000000; ">res;<br></span><span style="color: #008080; ">46</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080; ">47</span>&nbsp;<span style="color: #000000; ">&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; ">,ans);<br></span><span style="color: #008080; ">48</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">0</span><span style="color: #000000; ">;<br></span><span style="color: #008080; ">49</span>&nbsp;<span style="color: #000000; ">}</span></div><img src ="http://www.cppblog.com/yzhw/aggbug/139737.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-02-05 01:20 <a href="http://www.cppblog.com/yzhw/archive/2011/02/05/139737.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku1894-1903 Northeastern Europe 2003 解题报告</title><link>http://www.cppblog.com/yzhw/archive/2011/02/04/139716.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Thu, 03 Feb 2011 17:08:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/02/04/139716.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/139716.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/02/04/139716.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/139716.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/139716.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Solved            ID            Title            Ratio(AC/att)                                                Yes            Problem A            Alternative Scale of Notation ...&nbsp;&nbsp;<a href='http://www.cppblog.com/yzhw/archive/2011/02/04/139716.html'>阅读全文</a><img src ="http://www.cppblog.com/yzhw/aggbug/139716.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-02-04 01:08 <a href="http://www.cppblog.com/yzhw/archive/2011/02/04/139716.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku2902 Intercepting Missiles 线段树+离散化+二分图匹配，注意C++短路</title><link>http://www.cppblog.com/yzhw/archive/2011/01/31/139648.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Mon, 31 Jan 2011 10:35:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/01/31/139648.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/139648.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/01/31/139648.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/139648.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/139648.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 题意：有b个炸弹，p个飞机，平行于x轴飞行，地面部署了m个导弹，只能垂直打。知道0时刻炸弹、飞机的坐标，以及导弹的坐标以及炸弹、导弹、飞机的速度，问不打到飞机的情况下最多能拦截多少导弹？给力条件：炸弹被导弹击中后，继续飞行，而导弹立刻消失。飞行物高度均不同有个注意点：注意C++中的短路问题，慎用两个函数相或、与，可能因此一个函数得不到执行，这个在线段树里是很麻烦的。宁可多写一步解法：上次比赛这题死...&nbsp;&nbsp;<a href='http://www.cppblog.com/yzhw/archive/2011/01/31/139648.html'>阅读全文</a><img src ="http://www.cppblog.com/yzhw/aggbug/139648.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-01-31 18:35 <a href="http://www.cppblog.com/yzhw/archive/2011/01/31/139648.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku2894-2903 Tehran 2005 比赛总结</title><link>http://www.cppblog.com/yzhw/archive/2011/01/31/139630.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Sun, 30 Jan 2011 17:59:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/01/31/139630.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/139630.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/01/31/139630.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/139630.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/139630.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Solved            ID            Title            Ratio(AC/att)                                                Yes            Problem A            Ancient Keyboard            10...&nbsp;&nbsp;<a href='http://www.cppblog.com/yzhw/archive/2011/01/31/139630.html'>阅读全文</a><img src ="http://www.cppblog.com/yzhw/aggbug/139630.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-01-31 01:59 <a href="http://www.cppblog.com/yzhw/archive/2011/01/31/139630.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku1245-1251 Mid-Central USA 2002 比赛总结</title><link>http://www.cppblog.com/yzhw/archive/2011/01/21/138992.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Thu, 20 Jan 2011 18:21:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/01/21/138992.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/138992.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/01/21/138992.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/138992.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/138992.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 第二次做比赛，有了viaxl的加入，有点动力                        SolvedIDTitle                        Ratio(AC/att)                                    Yes            Problem A            Pr...&nbsp;&nbsp;<a href='http://www.cppblog.com/yzhw/archive/2011/01/21/138992.html'>阅读全文</a><img src ="http://www.cppblog.com/yzhw/aggbug/138992.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-01-21 02:21 <a href="http://www.cppblog.com/yzhw/archive/2011/01/21/138992.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku 1235 Galactic Breakup 并查集</title><link>http://www.cppblog.com/yzhw/archive/2011/01/20/138980.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Thu, 20 Jan 2011 12:44:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/01/20/138980.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/138980.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/01/20/138980.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/138980.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/138980.html</trackback:ping><description><![CDATA[
题意：<br>一个帝国有N个国家组成，每个国家包括N<sub>i</sub>个区域（一个小方格），然后第i个国家在第i月会分离出去。问有多少个月帝国仍然是一个整体。<br>PS：说道帝国，就想到黄金雄教授在ICPC开幕式上用闽南语讲的（。。。ACM大帝国。。），那发音，拿语言的组织都超级搞笑<br><img src="http://poj.org/images/1235_1.jpg" id="" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""><br><br>思路：<br>并查集，逆向思维。最后所有的国家应该都是独立的。相当于一个国家一个国家逐月的联合起来。用并查集统计是否当前集合为一个整体即可。暴力的方法没实验过，不过复杂度会高达30^6，(*^__^*) 嘻嘻&#8230;&#8230;，RP好的可以去拼一下～<br><br>代码：<br><div style="background-color: rgb(238, 238, 238); font-size: 13px; border-left-color: rgb(204, 204, 204); padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; "><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080; ">&nbsp;1</span>&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">============================================================================<br></span><span style="color: #008080; ">&nbsp;2</span>&nbsp;<span style="color: #008000; "></span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;pku1235.cpp<br></span><span style="color: #008080; ">&nbsp;3</span>&nbsp;<span style="color: #008000; "></span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;Author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;yzhw<br></span><span style="color: #008080; ">&nbsp;4</span>&nbsp;<span style="color: #008000; "></span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;Version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:<br></span><span style="color: #008080; ">&nbsp;5</span>&nbsp;<span style="color: #008000; "></span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;Copyright&nbsp;&nbsp;&nbsp;:&nbsp;yzhw<br></span><span style="color: #008080; ">&nbsp;6</span>&nbsp;<span style="color: #008000; "></span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;Description&nbsp;:&nbsp;Hello&nbsp;World&nbsp;in&nbsp;C++,&nbsp;Ansi-style<br></span><span style="color: #008080; ">&nbsp;7</span>&nbsp;<span style="color: #008000; "></span><span style="color: #008000; ">//</span><span style="color: #008000; ">============================================================================</span><span style="color: #008000; "><br></span><span style="color: #008080; ">&nbsp;8</span>&nbsp;<span style="color: #008000; "></span><span style="color: #000000; "><br></span><span style="color: #008080; ">&nbsp;9</span>&nbsp;<span style="color: #000000; ">#include&nbsp;</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: #008080; ">10</span>&nbsp;<span style="color: #000000; ">#include&nbsp;</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">cstdio</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br></span><span style="color: #008080; ">11</span>&nbsp;<span style="color: #000000; ">#include&nbsp;</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: #008080; ">12</span>&nbsp;<span style="color: #000000; ">#include&nbsp;</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">algorithm</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br></span><span style="color: #008080; ">13</span>&nbsp;<span style="color: #000000; "></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: #008080; ">14</span>&nbsp;<span style="color: #000000; ">#&nbsp;define&nbsp;LEFT&nbsp;(data[i][j]</span><span style="color: #000000; ">%</span><span style="color: #000000; ">(n</span><span style="color: #000000; ">*</span><span style="color: #000000; ">m))<br></span><span style="color: #008080; ">15</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">set</span><span style="color: #000000; ">[</span><span style="color: #000000; ">30000</span><span style="color: #000000; ">],n,m,k,l,data[</span><span style="color: #000000; ">30000</span><span style="color: #000000; ">][</span><span style="color: #000000; ">21</span><span style="color: #000000; ">];<br></span><span style="color: #008080; ">16</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">bool</span><span style="color: #000000; ">&nbsp;used[</span><span style="color: #000000; ">30000</span><span style="color: #000000; ">];<br></span><span style="color: #008080; ">17</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;find(</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;pos)<br></span><span style="color: #008080; ">18</span>&nbsp;<span style="color: #000000; ">{<br></span><span style="color: #008080; ">19</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(</span><span style="color: #0000FF; ">set</span><span style="color: #000000; ">[pos]</span><span style="color: #000000; ">==</span><span style="color: #000000; ">pos)&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">&nbsp;pos;<br></span><span style="color: #008080; ">20</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">else</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">set</span><span style="color: #000000; ">[pos]</span><span style="color: #000000; ">=</span><span style="color: #000000; ">find(</span><span style="color: #0000FF; ">set</span><span style="color: #000000; ">[pos]);<br></span><span style="color: #008080; ">21</span>&nbsp;<span style="color: #000000; ">}<br></span><span style="color: #008080; ">22</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;main()&nbsp;{<br></span><span style="color: #008080; ">23</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;testcase;<br></span><span style="color: #008080; ">24</span>&nbsp;<span style="color: #000000; ">&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; ">testcase);<br></span><span style="color: #008080; ">25</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">while</span><span style="color: #000000; ">(testcase</span><span style="color: #000000; ">--</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">26</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080; ">27</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">%d%d%d%d</span><span style="color: #000000; ">"</span><span style="color: #000000; ">,</span><span style="color: #000000; ">&amp;</span><span style="color: #000000; ">n,</span><span style="color: #000000; ">&amp;</span><span style="color: #000000; ">m,</span><span style="color: #000000; ">&amp;</span><span style="color: #000000; ">k,</span><span style="color: #000000; ">&amp;</span><span style="color: #000000; ">l);<br></span><span style="color: #008080; ">28</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;total</span><span style="color: #000000; ">=</span><span style="color: #000000; ">0</span><span style="color: #000000; ">,ans</span><span style="color: #000000; ">=</span><span style="color: #000000; ">0</span><span style="color: #000000; ">,c;<br></span><span style="color: #008080; ">29</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&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; ">n</span><span style="color: #000000; ">*</span><span style="color: #000000; ">m</span><span style="color: #000000; ">*</span><span style="color: #000000; ">k;i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">30</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">set</span><span style="color: #000000; ">[i]</span><span style="color: #000000; ">=</span><span style="color: #000000; ">i,used[i]</span><span style="color: #000000; ">=</span><span style="color: #0000FF; ">false</span><span style="color: #000000; ">;<br></span><span style="color: #008080; ">31</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&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; ">l;i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">32</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080; ">33</span>&nbsp;<span style="color: #000000; ">&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; ">data[i][</span><span style="color: #000000; ">0</span><span style="color: #000000; ">]);<br></span><span style="color: #008080; ">34</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;j</span><span style="color: #000000; ">=</span><span style="color: #000000; ">1</span><span style="color: #000000; ">;j</span><span style="color: #000000; ">&lt;=</span><span style="color: #000000; ">data[i][</span><span style="color: #000000; ">0</span><span style="color: #000000; ">];j</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">35</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&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; ">data[i][j]);<br></span><span style="color: #008080; ">36</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080; ">37</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&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; ">l</span><span style="color: #000000; ">-</span><span style="color: #000000; ">1</span><span style="color: #000000; ">;i</span><span style="color: #000000; ">&gt;=</span><span style="color: #000000; ">0</span><span style="color: #000000; ">;i</span><span style="color: #000000; ">--</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">38</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080; ">39</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="color: #000000; ">=</span><span style="color: #000000; ">0</span><span style="color: #000000; ">;<br></span><span style="color: #008080; ">40</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;j</span><span style="color: #000000; ">=</span><span style="color: #000000; ">1</span><span style="color: #000000; ">;j</span><span style="color: #000000; ">&lt;=</span><span style="color: #000000; ">data[i][</span><span style="color: #000000; ">0</span><span style="color: #000000; ">];j</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">41</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080; ">42</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="color: #000000; ">&lt;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; ">&nbsp;refer;<br></span><span style="color: #008080; ">43</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(data[i][j]</span><span style="color: #000000; ">-</span><span style="color: #000000; ">n</span><span style="color: #000000; ">*</span><span style="color: #000000; ">m</span><span style="color: #000000; ">&gt;=</span><span style="color: #000000; ">0</span><span style="color: #000000; ">&amp;&amp;</span><span style="color: #000000; ">used[data[i][j]</span><span style="color: #000000; ">-</span><span style="color: #000000; ">n</span><span style="color: #000000; ">*</span><span style="color: #000000; ">m])&nbsp;refer.push_back(find(data[i][j]</span><span style="color: #000000; ">-</span><span style="color: #000000; ">n</span><span style="color: #000000; ">*</span><span style="color: #000000; ">m));<br></span><span style="color: #008080; ">44</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(data[i][j]</span><span style="color: #000000; ">+</span><span style="color: #000000; ">n</span><span style="color: #000000; ">*</span><span style="color: #000000; ">m</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">n</span><span style="color: #000000; ">*</span><span style="color: #000000; ">m</span><span style="color: #000000; ">*</span><span style="color: #000000; ">k</span><span style="color: #000000; ">&amp;&amp;</span><span style="color: #000000; ">used[data[i][j]</span><span style="color: #000000; ">+</span><span style="color: #000000; ">n</span><span style="color: #000000; ">*</span><span style="color: #000000; ">m])&nbsp;refer.push_back(find(data[i][j]</span><span style="color: #000000; ">+</span><span style="color: #000000; ">n</span><span style="color: #000000; ">*</span><span style="color: #000000; ">m));<br></span><span style="color: #008080; ">45</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(LEFT</span><span style="color: #000000; ">%</span><span style="color: #000000; ">n</span><span style="color: #000000; ">!=</span><span style="color: #000000; ">0</span><span style="color: #000000; ">&amp;&amp;</span><span style="color: #000000; ">used[data[i][j]</span><span style="color: #000000; ">-</span><span style="color: #000000; ">1</span><span style="color: #000000; ">])&nbsp;refer.push_back(find(data[i][j]</span><span style="color: #000000; ">-</span><span style="color: #000000; ">1</span><span style="color: #000000; ">));<br></span><span style="color: #008080; ">46</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(LEFT</span><span style="color: #000000; ">%</span><span style="color: #000000; ">n</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; ">&amp;&amp;</span><span style="color: #000000; ">used[data[i][j]</span><span style="color: #000000; ">+</span><span style="color: #000000; ">1</span><span style="color: #000000; ">])&nbsp;refer.push_back(find(data[i][j]</span><span style="color: #000000; ">+</span><span style="color: #000000; ">1</span><span style="color: #000000; ">));<br></span><span style="color: #008080; ">47</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(LEFT</span><span style="color: #000000; ">/</span><span style="color: #000000; ">n</span><span style="color: #000000; ">!=</span><span style="color: #000000; ">0</span><span style="color: #000000; ">&amp;&amp;</span><span style="color: #000000; ">used[data[i][j]</span><span style="color: #000000; ">-</span><span style="color: #000000; ">n])&nbsp;refer.push_back(find(data[i][j]</span><span style="color: #000000; ">-</span><span style="color: #000000; ">n));<br></span><span style="color: #008080; ">48</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(LEFT</span><span style="color: #000000; ">/</span><span style="color: #000000; ">n</span><span style="color: #000000; ">!=</span><span style="color: #000000; ">m</span><span style="color: #000000; ">-</span><span style="color: #000000; ">1</span><span style="color: #000000; ">&amp;&amp;</span><span style="color: #000000; ">used[data[i][j]</span><span style="color: #000000; ">+</span><span style="color: #000000; ">n])&nbsp;refer.push_back(find(data[i][j]</span><span style="color: #000000; ">+</span><span style="color: #000000; ">n));<br></span><span style="color: #008080; ">49</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort(refer.begin(),refer.end());<br></span><span style="color: #008080; ">50</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="color: #000000; ">&lt;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; ">::iterator&nbsp;end</span><span style="color: #000000; ">=</span><span style="color: #000000; ">unique(refer.begin(),refer.end());<br></span><span style="color: #008080; ">51</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="color: #000000; ">+=</span><span style="color: #000000; ">end</span><span style="color: #000000; ">-</span><span style="color: #000000; ">refer.begin();<br></span><span style="color: #008080; ">52</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;t</span><span style="color: #000000; ">=</span><span style="color: #000000; ">0</span><span style="color: #000000; ">;t</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">end</span><span style="color: #000000; ">-</span><span style="color: #000000; ">refer.begin();t</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br></span><span style="color: #008080; ">53</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">set</span><span style="color: #000000; ">[find(refer[t])]</span><span style="color: #000000; ">=</span><span style="color: #000000; ">find(data[i][j]);<br></span><span style="color: #008080; ">54</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;used[data[i][j]]</span><span style="color: #000000; ">=</span><span style="color: #0000FF; ">true</span><span style="color: #000000; ">;<br></span><span style="color: #008080; ">55</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080; ">56</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;total</span><span style="color: #000000; ">=</span><span style="color: #000000; ">total</span><span style="color: #000000; ">+</span><span style="color: #000000; ">data[i][</span><span style="color: #000000; ">0</span><span style="color: #000000; ">]</span><span style="color: #000000; ">-</span><span style="color: #000000; ">c;<br></span><span style="color: #008080; ">57</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(total</span><span style="color: #000000; ">==</span><span style="color: #000000; ">1</span><span style="color: #000000; ">)&nbsp;ans</span><span style="color: #000000; ">++</span><span style="color: #000000; ">;<br></span><span style="color: #008080; ">58</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080; ">59</span>&nbsp;<span style="color: #000000; ">&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; ">,l</span><span style="color: #000000; ">-</span><span style="color: #000000; ">ans);<br></span><span style="color: #008080; ">60</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080; ">61</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">0</span><span style="color: #000000; ">;<br></span><span style="color: #008080; ">62</span>&nbsp;<span style="color: #000000; ">}</span></div><img src ="http://www.cppblog.com/yzhw/aggbug/138980.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-01-20 20:44 <a href="http://www.cppblog.com/yzhw/archive/2011/01/20/138980.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku 1241 Knockout Tournament 树形DP，很好的题目</title><link>http://www.cppblog.com/yzhw/archive/2011/01/20/138937.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Wed, 19 Jan 2011 17:44:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/01/20/138937.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/138937.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/01/20/138937.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/138937.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/138937.html</trackback:ping><description><![CDATA[题意：<br><img border=0 hspace=0 alt="" align=baseline src="http://poj.org/images/1241_1.jpg" longDesc=""><br>看图说话，一棵锦标赛树（具体不描述，看DS书去），问每个队员的最好名次和最坏名次<br><br>分析：<br>求最好名次应该从上向下划分状态，而求最坏名次从下向上划分状态，举个例子吧，看第三排第一个1，它的最坏名次是第四排第一个1的最坏名次加上它的1^n-右孩子的最坏名次-1，而它的最好名次则是第二排第一个1的最好名次，它旁边那个3的最好名次就是3的父节点（1）的最好名次+1，大概明白什么意思了吧？看代码吧～。<br><br>代码：<br>
<div style="PADDING-BOTTOM: 4px; BACKGROUND-COLOR: rgb(238,238,238); PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; BORDER-LEFT-COLOR: rgb(204,204,204); WORD-BREAK: break-all; PADDING-TOP: 4px"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="COLOR: #008080">&nbsp;1</span>&nbsp;<span style="COLOR: #000000">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstdio</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;2</span>&nbsp;<span style="COLOR: #000000">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstring</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;3</span>&nbsp;<span style="COLOR: #000000"></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: #008080">&nbsp;4</span>&nbsp;<span style="COLOR: #000000">#&nbsp;define&nbsp;max(a,b)&nbsp;((a)</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">(b)</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">(a):(b))<br></span><span style="COLOR: #008080">&nbsp;5</span>&nbsp;<span style="COLOR: #000000">#&nbsp;define&nbsp;min(a,b)&nbsp;((a)</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">(b)</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">(a):(b))<br></span><span style="COLOR: #008080">&nbsp;6</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;tree[</span><span style="COLOR: #000000">1024</span><span style="COLOR: #000000">],n;<br></span><span style="COLOR: #008080">&nbsp;7</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;worst[</span><span style="COLOR: #000000">1024</span><span style="COLOR: #000000">],best[</span><span style="COLOR: #000000">1024</span><span style="COLOR: #000000">],high[</span><span style="COLOR: #000000">1024</span><span style="COLOR: #000000">],low[</span><span style="COLOR: #000000">1024</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">&nbsp;8</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br></span><span style="COLOR: #008080">&nbsp;9</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">10</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">11</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">12</span>&nbsp;<span style="COLOR: #000000">&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">n);<br></span><span style="COLOR: #008080">13</span>&nbsp;<span style="COLOR: #000000">&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">n)&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">14</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&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">1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">(n</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">15</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tree[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">n),worst[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">n;<br></span><span style="COLOR: #008080">16</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&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;t</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">;t</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;t</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">17</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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">1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">t;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">(t</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">18</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">19</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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">,tree</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i);<br></span><span style="COLOR: #008080">20</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;worst[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(tree[i]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">tree[i</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">worst[i</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">n)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">worst[(i</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]:worst[(i</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">n)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">worst[i</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">21</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">22</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;best[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">23</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&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">2</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">(n</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">24</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;best[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(tree[i]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">tree[i</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">best[i</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]:best[i</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">25</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&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">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">(n</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">26</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;high[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">low[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">n;<br></span><span style="COLOR: #008080">27</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&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">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">(n</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">28</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">29</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;high[tree[i]]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">min(high[tree[i]],best[i]);<br></span><span style="COLOR: #008080">30</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;low[tree[i]]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">min(low[tree[i]],worst[i]);<br></span><span style="COLOR: #008080">31</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">32</span>&nbsp;<span style="COLOR: #000000">&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">n);<br></span><span style="COLOR: #008080">33</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(n</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">34</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">35</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;t;<br></span><span style="COLOR: #008080">36</span>&nbsp;<span style="COLOR: #000000">&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">t);<br></span><span style="COLOR: #008080">37</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Player&nbsp;%d&nbsp;can&nbsp;be&nbsp;ranked&nbsp;as&nbsp;high&nbsp;as&nbsp;%d&nbsp;or&nbsp;as&nbsp;low&nbsp;as&nbsp;%d.\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,t,high[t],low[t]);<br></span><span style="COLOR: #008080">38</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">39</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&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></span><span style="COLOR: #008080">40</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">41</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">42</span>&nbsp;<span style="COLOR: #000000">}</span></div>
<br><br>
<img src ="http://www.cppblog.com/yzhw/aggbug/138937.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-01-20 01:44 <a href="http://www.cppblog.com/yzhw/archive/2011/01/20/138937.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku 1231 The Alphabet Game 很好的数据结构题目</title><link>http://www.cppblog.com/yzhw/archive/2011/01/17/138621.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Sun, 16 Jan 2011 16:55:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/01/17/138621.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/138621.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/01/17/138621.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/138621.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/138621.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 题意是这样：一个格板上写有k*n个字母，第i个字母有k个。然后问能否用贯穿整个方格板的横线和竖线将不同的字母分开。解法：首先，假设我们将k个同一个字母用一个n*m的矩形框框住，这题就转换为这样一个问题：平面上给出一些矩形，能否用用一些水平或竖直线将平面划分开，使得每一个区域中有且仅有一个矩形。下面的想法就有点巧妙，首先，横向的切割与纵向的切割是相互独立的，就是说，无论水平线怎么画与竖直线的安排无关...&nbsp;&nbsp;<a href='http://www.cppblog.com/yzhw/archive/2011/01/17/138621.html'>阅读全文</a><img src ="http://www.cppblog.com/yzhw/aggbug/138621.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-01-17 00:55 <a href="http://www.cppblog.com/yzhw/archive/2011/01/17/138621.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku1223 DEHUFF 哈夫曼树确定，PKU1261简化版</title><link>http://www.cppblog.com/yzhw/archive/2011/01/16/138595.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Sun, 16 Jan 2011 06:01:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/01/16/138595.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/138595.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/01/16/138595.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/138595.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/138595.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 题目描述：一个哈夫曼树，给出一个字符串以及编码，要求确定哈夫曼树如果无解或者多解，输出MULTIPLE TABLES解法：同pku1261，那题我写了详细的报告，http://www.cppblog.com/yzhw/archive/2011/01/11/138368.aspx代码：&nbsp;&nbsp;1#&nbsp;include&nbsp;&lt;cstdio&gt;&nbsp;&nb...&nbsp;&nbsp;<a href='http://www.cppblog.com/yzhw/archive/2011/01/16/138595.html'>阅读全文</a><img src ="http://www.cppblog.com/yzhw/aggbug/138595.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-01-16 14:01 <a href="http://www.cppblog.com/yzhw/archive/2011/01/16/138595.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku 1214 "Accordian" Patience STL+模拟</title><link>http://www.cppblog.com/yzhw/archive/2011/01/13/138481.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Thu, 13 Jan 2011 13:28:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/01/13/138481.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/138481.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/01/13/138481.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/138481.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/138481.html</trackback:ping><description><![CDATA[题意：<br>
<p><font size=3>你的任务是模拟一种叫「Accordian」的纸牌游戏，他的游戏规则如下： </font></p>
<p><font size=3>一副扑克牌有52张牌，首先把纸牌一张一张由左到右排好（不能有重叠，所以共有52堆牌，每堆一张），当某一张牌与他左边那张牌或者左边的第三张牌有「Match」的时候，就把这张牌移到那张牌上面去。在这里两张牌「Match」指的是这两张牌的花色（suit）或者点数（rank）一样。当你做了一个移动之后，要察看是否还可以做其他的移动。<font color=#ff0000>在任何时间，只有最上面那张牌可以被移动。</font>如果因为移动一张牌使得产生一个空格（也就是被移动的那堆牌只有一张牌），你必须把右边所有的牌堆往左移一格。如此不断的寻找可移动的牌，直到没有一张牌可以移动游戏就结束了。 </font></p>
<p><font size=3>在选择可以移动的牌的时候可能有些状况会发生。<font color=#ff0000>如果有两张牌都可以移动，你应该要移动最左边的那张牌。当一张牌可以被移动到左边一格，或左边三格的时候，你必须移动到左边三格</font></font></p>
解法：<br>纯模拟，外层用STL set，内层用STL stack，然后就是各种调用，各种迭代器~<br><br>代码：<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">list</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</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: #008080">&nbsp;3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstdio</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">algorithm</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></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: #008080">&nbsp;6</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">list</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">pair</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;l;<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img id=Codehighlighter1_144_1491_Open_Image onclick="this.style.display='none'; Codehighlighter1_144_1491_Open_Text.style.display='none'; Codehighlighter1_144_1491_Closed_Image.style.display='inline'; Codehighlighter1_144_1491_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_144_1491_Closed_Image onclick="this.style.display='none'; Codehighlighter1_144_1491_Closed_Text.style.display='none'; Codehighlighter1_144_1491_Open_Image.style.display='inline'; Codehighlighter1_144_1491_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_144_1491_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_144_1491_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">pair</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">t;<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img id=Codehighlighter1_188_1489_Open_Image onclick="this.style.display='none'; Codehighlighter1_188_1489_Open_Text.style.display='none'; Codehighlighter1_188_1489_Closed_Image.style.display='inline'; Codehighlighter1_188_1489_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_188_1489_Closed_Image onclick="this.style.display='none'; Codehighlighter1_188_1489_Closed_Text.style.display='none'; Codehighlighter1_188_1489_Open_Image.style.display='inline'; Codehighlighter1_188_1489_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_188_1489_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_188_1489_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;tmp[</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,tmp);<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(tmp[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">#</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.clear();<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l.clear();<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.push_back(pair</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">(tmp[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">],tmp[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]));<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l.push_back(t);<br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&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">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">52</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img id=Codehighlighter1_366_471_Open_Image onclick="this.style.display='none'; Codehighlighter1_366_471_Open_Text.style.display='none'; Codehighlighter1_366_471_Closed_Image.style.display='inline'; Codehighlighter1_366_471_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_366_471_Closed_Image onclick="this.style.display='none'; Codehighlighter1_366_471_Closed_Text.style.display='none'; Codehighlighter1_366_471_Open_Image.style.display='inline'; Codehighlighter1_366_471_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_366_471_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_366_471_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.clear();<br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,tmp);<br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.push_back(pair</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">(tmp[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">],tmp[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]));<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l.push_back(t);<br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img id=Codehighlighter1_489_1323_Open_Image onclick="this.style.display='none'; Codehighlighter1_489_1323_Open_Text.style.display='none'; Codehighlighter1_489_1323_Closed_Image.style.display='inline'; Codehighlighter1_489_1323_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_489_1323_Closed_Image onclick="this.style.display='none'; Codehighlighter1_489_1323_Closed_Text.style.display='none'; Codehighlighter1_489_1323_Open_Image.style.display='inline'; Codehighlighter1_489_1323_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_489_1323_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_489_1323_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(list</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">pair</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">::iterator&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">l.begin();i</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">l.end()</span><span style="COLOR: #000000">&amp;&amp;!</span><span style="COLOR: #000000">flag;)<br></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img id=Codehighlighter1_595_1299_Open_Image onclick="this.style.display='none'; Codehighlighter1_595_1299_Open_Text.style.display='none'; Codehighlighter1_595_1299_Closed_Image.style.display='inline'; Codehighlighter1_595_1299_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_595_1299_Closed_Image onclick="this.style.display='none'; Codehighlighter1_595_1299_Closed_Text.style.display='none'; Codehighlighter1_595_1299_Open_Image.style.display='inline'; Codehighlighter1_595_1299_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_595_1299_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_595_1299_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;count</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">32</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;remove</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">33</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">pair</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">::iterator&nbsp;i3</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;<br></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(i3</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">l.begin()</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">count</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">35</span><span style="COLOR: #000000"><img id=Codehighlighter1_727_758_Open_Image onclick="this.style.display='none'; Codehighlighter1_727_758_Open_Text.style.display='none'; Codehighlighter1_727_758_Closed_Image.style.display='inline'; Codehighlighter1_727_758_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_727_758_Closed_Image onclick="this.style.display='none'; Codehighlighter1_727_758_Closed_Text.style.display='none'; Codehighlighter1_727_758_Open_Image.style.display='inline'; Codehighlighter1_727_758_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_727_758_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_727_758_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">36</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">37</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i3</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">38</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">39</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(count</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">(i3</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">back().first</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">back().first</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">i3</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">back().second</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">back().second))<br></span><span style="COLOR: #008080">40</span><span style="COLOR: #000000"><img id=Codehighlighter1_855_974_Open_Image onclick="this.style.display='none'; Codehighlighter1_855_974_Open_Text.style.display='none'; Codehighlighter1_855_974_Closed_Image.style.display='inline'; Codehighlighter1_855_974_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_855_974_Closed_Image onclick="this.style.display='none'; Codehighlighter1_855_974_Closed_Text.style.display='none'; Codehighlighter1_855_974_Open_Image.style.display='inline'; Codehighlighter1_855_974_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_855_974_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_855_974_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">41</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i3</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">push_back(i</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">back());<br></span><span style="COLOR: #008080">42</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">pop_back();<br></span><span style="COLOR: #008080">43</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">empty())&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">l.erase(i),remove</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">44</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">45</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">46</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">47</span><span style="COLOR: #000000"><img id=Codehighlighter1_989_1273_Open_Image onclick="this.style.display='none'; Codehighlighter1_989_1273_Open_Text.style.display='none'; Codehighlighter1_989_1273_Closed_Image.style.display='inline'; Codehighlighter1_989_1273_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_989_1273_Closed_Image onclick="this.style.display='none'; Codehighlighter1_989_1273_Closed_Text.style.display='none'; Codehighlighter1_989_1273_Open_Image.style.display='inline'; Codehighlighter1_989_1273_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_989_1273_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_989_1273_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">48</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i3</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;<br></span><span style="COLOR: #008080">49</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i3</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">l.begin())<br></span><span style="COLOR: #008080">50</span><span style="COLOR: #000000"><img id=Codehighlighter1_1030_1267_Open_Image onclick="this.style.display='none'; Codehighlighter1_1030_1267_Open_Text.style.display='none'; Codehighlighter1_1030_1267_Closed_Image.style.display='inline'; Codehighlighter1_1030_1267_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1030_1267_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1030_1267_Closed_Text.style.display='none'; Codehighlighter1_1030_1267_Open_Image.style.display='inline'; Codehighlighter1_1030_1267_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1030_1267_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1030_1267_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">51</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i3</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">52</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i3</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">back().first</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">back().first</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">i3</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">back().second</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">back().second)<br></span><span style="COLOR: #008080">53</span><span style="COLOR: #000000"><img id=Codehighlighter1_1131_1260_Open_Image onclick="this.style.display='none'; Codehighlighter1_1131_1260_Open_Text.style.display='none'; Codehighlighter1_1131_1260_Closed_Image.style.display='inline'; Codehighlighter1_1131_1260_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1131_1260_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1131_1260_Closed_Text.style.display='none'; Codehighlighter1_1131_1260_Open_Image.style.display='inline'; Codehighlighter1_1131_1260_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&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><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1131_1260_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1131_1260_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">54</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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;i3</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">push_back(i</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">back());<br></span><span style="COLOR: #008080">55</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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;i</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">pop_back();<br></span><span style="COLOR: #008080">56</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">empty())&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">l.erase(i),remove</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">57</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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;flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">58</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&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></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">59</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">60</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">61</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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">remove)&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">62</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">63</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&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">flag)&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">64</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">65</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d&nbsp;piles&nbsp;remaining:</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,l.size());<br></span><span style="COLOR: #008080">66</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(list</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">pair</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">::iterator&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">l.begin();i</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">l.end();i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">67</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&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">,i</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">size());<br></span><span style="COLOR: #008080">68</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&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></span><span style="COLOR: #008080">69</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">70</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">71</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
<img src ="http://www.cppblog.com/yzhw/aggbug/138481.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-01-13 21:28 <a href="http://www.cppblog.com/yzhw/archive/2011/01/13/138481.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku3630 Phone List 字典树+判断前缀 经典入门题</title><link>http://www.cppblog.com/yzhw/archive/2011/01/12/138374.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Tue, 11 Jan 2011 16:11:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/01/12/138374.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/138374.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/01/12/138374.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/138374.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/138374.html</trackback:ping><description><![CDATA[题意：<br>给出一堆电话号码，判断是否存在某个号码是另一个号码的前缀<br><br>题解：<br>还是通过字典树，不过判断的时候不能够仅仅判断当前待插入字符串的路径上是否包含结束标记（如果事先对字符转进行了按长短排序就没问题了），而需要记录每个节点包含的路径条数，如果在待插入字符串的尾节点（即结束标记节点上通过的路径数大于1，则说明有路径覆盖了这个节点，即有一个字符转以当前字符串为前缀，故不可能）<br><br>代码：<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000">&nbsp;java.io.</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Dic_Tree<br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img id=Codehighlighter1_33_491_Open_Image onclick="this.style.display='none'; Codehighlighter1_33_491_Open_Text.style.display='none'; Codehighlighter1_33_491_Closed_Image.style.display='inline'; Codehighlighter1_33_491_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_33_491_Closed_Image onclick="this.style.display='none'; Codehighlighter1_33_491_Closed_Text.style.display='none'; Codehighlighter1_33_491_Open_Image.style.display='inline'; Codehighlighter1_33_491_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_33_491_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_33_491_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;node<br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img id=Codehighlighter1_48_114_Open_Image onclick="this.style.display='none'; Codehighlighter1_48_114_Open_Text.style.display='none'; Codehighlighter1_48_114_Closed_Image.style.display='inline'; Codehighlighter1_48_114_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_48_114_Closed_Image onclick="this.style.display='none'; Codehighlighter1_48_114_Closed_Text.style.display='none'; Codehighlighter1_48_114_Open_Image.style.display='inline'; Codehighlighter1_48_114_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_48_114_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_48_114_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;node&nbsp;nxt[]</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;node[</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000">&nbsp;end</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;count</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;node&nbsp;head</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;clear()<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img id=Codehighlighter1_148_170_Open_Image onclick="this.style.display='none'; Codehighlighter1_148_170_Open_Text.style.display='none'; Codehighlighter1_148_170_Closed_Image.style.display='inline'; Codehighlighter1_148_170_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_148_170_Closed_Image onclick="this.style.display='none'; Codehighlighter1_148_170_Closed_Text.style.display='none'; Codehighlighter1_148_170_Open_Image.style.display='inline'; Codehighlighter1_148_170_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_148_170_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_148_170_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;head</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;node();<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000">&nbsp;insert(String&nbsp;str)<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img id=Codehighlighter1_201_487_Open_Image onclick="this.style.display='none'; Codehighlighter1_201_487_Open_Text.style.display='none'; Codehighlighter1_201_487_Closed_Image.style.display='inline'; Codehighlighter1_201_487_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_201_487_Closed_Image onclick="this.style.display='none'; Codehighlighter1_201_487_Closed_Text.style.display='none'; Codehighlighter1_201_487_Open_Image.style.display='inline'; Codehighlighter1_201_487_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_201_487_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_201_487_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;node&nbsp;p</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">head;<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&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">str.length();i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img id=Codehighlighter1_254_406_Open_Image onclick="this.style.display='none'; Codehighlighter1_254_406_Open_Text.style.display='none'; Codehighlighter1_254_406_Closed_Image.style.display='inline'; Codehighlighter1_254_406_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_254_406_Closed_Image onclick="this.style.display='none'; Codehighlighter1_254_406_Closed_Text.style.display='none'; Codehighlighter1_254_406_Open_Image.style.display='inline'; Codehighlighter1_254_406_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_254_406_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_254_406_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p.count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(p.end)&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(p.nxt[str.charAt(i)</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">48</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">==</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p.nxt[str.charAt(i)</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">48</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;node();<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">p.nxt[str.charAt(i)</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">48</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p.count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(p.count</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p.end</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">32</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">33</span><span style="COLOR: #000000"><img id=Codehighlighter1_511_1078_Open_Image onclick="this.style.display='none'; Codehighlighter1_511_1078_Open_Text.style.display='none'; Codehighlighter1_511_1078_Closed_Image.style.display='inline'; Codehighlighter1_511_1078_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_511_1078_Closed_Image onclick="this.style.display='none'; Codehighlighter1_511_1078_Closed_Text.style.display='none'; Codehighlighter1_511_1078_Open_Image.style.display='inline'; Codehighlighter1_511_1078_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Main&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_511_1078_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_511_1078_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br></span><span style="COLOR: #008080">35</span><span style="COLOR: #000000"><img id=Codehighlighter1_515_538_Open_Image onclick="this.style.display='none'; Codehighlighter1_515_538_Open_Text.style.display='none'; Codehighlighter1_515_538_Closed_Image.style.display='inline'; Codehighlighter1_515_538_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_515_538_Closed_Image onclick="this.style.display='none'; Codehighlighter1_515_538_Closed_Text.style.display='none'; Codehighlighter1_515_538_Open_Image.style.display='inline'; Codehighlighter1_515_538_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_515_538_Closed_Text>/**&nbsp;*/</span><span id=Codehighlighter1_515_538_Open_Text><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">36</span><span style="COLOR: #008000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000">&nbsp;args<br></span><span style="COLOR: #008080">37</span><span style="COLOR: #008000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">38</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;Dic_Tree&nbsp;data</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;Dic_Tree();<br></span><span style="COLOR: #008080">39</span><span style="COLOR: #000000"><img id=Codehighlighter1_636_1075_Open_Image onclick="this.style.display='none'; Codehighlighter1_636_1075_Open_Text.style.display='none'; Codehighlighter1_636_1075_Closed_Image.style.display='inline'; Codehighlighter1_636_1075_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_636_1075_Closed_Image onclick="this.style.display='none'; Codehighlighter1_636_1075_Closed_Text.style.display='none'; Codehighlighter1_636_1075_Open_Image.style.display='inline'; Codehighlighter1_636_1075_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;main(String[]&nbsp;args)&nbsp;</span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000">&nbsp;IOException</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_636_1075_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_636_1075_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">40</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BufferedReader&nbsp;in</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;BufferedReader(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;InputStreamReader(System.in));<br></span><span style="COLOR: #008080">41</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;test</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Integer.parseInt(in.readLine());<br></span><span style="COLOR: #008080">42</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">((test</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">43</span><span style="COLOR: #000000"><img id=Codehighlighter1_779_1071_Open_Image onclick="this.style.display='none'; Codehighlighter1_779_1071_Open_Text.style.display='none'; Codehighlighter1_779_1071_Closed_Image.style.display='inline'; Codehighlighter1_779_1071_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_779_1071_Closed_Image onclick="this.style.display='none'; Codehighlighter1_779_1071_Closed_Text.style.display='none'; Codehighlighter1_779_1071_Open_Image.style.display='inline'; Codehighlighter1_779_1071_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_779_1071_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_779_1071_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">44</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;num</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Integer.parseInt(in.readLine());<br></span><span style="COLOR: #008080">45</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000">&nbsp;flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">46</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data.clear();<br></span><span style="COLOR: #008080">47</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">((num</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">48</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(flag)<br></span><span style="COLOR: #008080">49</span><span style="COLOR: #000000"><img id=Codehighlighter1_904_959_Open_Image onclick="this.style.display='none'; Codehighlighter1_904_959_Open_Text.style.display='none'; Codehighlighter1_904_959_Closed_Image.style.display='inline'; Codehighlighter1_904_959_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_904_959_Closed_Image onclick="this.style.display='none'; Codehighlighter1_904_959_Closed_Text.style.display='none'; Codehighlighter1_904_959_Open_Image.style.display='inline'; Codehighlighter1_904_959_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_904_959_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_904_959_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">50</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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">data.insert(in.readLine()))&nbsp;flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">51</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">52</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">53</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;in.readLine();<br></span><span style="COLOR: #008080">54</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(flag)&nbsp;System.out.println(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">YES</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">55</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;System.out.println(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">NO</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">56</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">57</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">58</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br></span><span style="COLOR: #008080">59</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">60</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br></span><span style="COLOR: #008080">61</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">62</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
<img src ="http://www.cppblog.com/yzhw/aggbug/138374.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-01-12 00:11 <a href="http://www.cppblog.com/yzhw/archive/2011/01/12/138374.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku1261 Huffman Trees 搜索与数据结构结合的好题</title><link>http://www.cppblog.com/yzhw/archive/2011/01/11/138368.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Tue, 11 Jan 2011 15:08:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/01/11/138368.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/138368.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/01/11/138368.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/138368.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/138368.html</trackback:ping><description><![CDATA[题意：<br>一棵K叉哈弗曼树，只有中间节点（满儿子）和叶节点两种。给出1-k的连续编码，求出哈弗曼树的结构。<br><br>解法：<br>首先要清楚，哈弗曼编码是一种没有公共前缀的编码，这提供了很重要的剪枝条件<br>另外，由于树中只含有满节点和空节点（叶子节点），故每分出一个枝条（从叶节点变为一棵子树）至少增加n-1个叶子节点。<br>利用以上两点，就可以很好的剪枝了。<br><br>剪枝判断还是通过字典树（额，这题中似乎叫哈弗曼树比较合适- -）。详细看程序吧。<br><br>代码：<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstdio</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstring</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;include&nbsp;</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: #008080">&nbsp;4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;</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: #008080">&nbsp;5</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;node<br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img id=Codehighlighter1_97_214_Open_Image onclick="this.style.display='none'; Codehighlighter1_97_214_Open_Text.style.display='none'; Codehighlighter1_97_214_Closed_Image.style.display='inline'; Codehighlighter1_97_214_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_97_214_Closed_Image onclick="this.style.display='none'; Codehighlighter1_97_214_Closed_Text.style.display='none'; Codehighlighter1_97_214_Open_Image.style.display='inline'; Codehighlighter1_97_214_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_97_214_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_97_214_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;node&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">nxt[</span><span style="COLOR: #000000">20</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;count;<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;end;<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;node()<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img id=Codehighlighter1_152_211_Open_Image onclick="this.style.display='none'; Codehighlighter1_152_211_Open_Text.style.display='none'; Codehighlighter1_152_211_Closed_Image.style.display='inline'; Codehighlighter1_152_211_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_152_211_Closed_Image onclick="this.style.display='none'; Codehighlighter1_152_211_Closed_Text.style.display='none'; Codehighlighter1_152_211_Open_Image.style.display='inline'; Codehighlighter1_152_211_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_152_211_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_152_211_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(nxt,NULL,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(nxt));<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;z,n,count,len,c;<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;node&nbsp;buffer[</span><span style="COLOR: #000000">100000</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;node&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">head;<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;str[</span><span style="COLOR: #000000">250</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;ans[</span><span style="COLOR: #000000">21</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;clear(node&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">p)<br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img id=Codehighlighter1_326_397_Open_Image onclick="this.style.display='none'; Codehighlighter1_326_397_Open_Text.style.display='none'; Codehighlighter1_326_397_Closed_Image.style.display='inline'; Codehighlighter1_326_397_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_326_397_Closed_Image onclick="this.style.display='none'; Codehighlighter1_326_397_Closed_Text.style.display='none'; Codehighlighter1_326_397_Open_Image.style.display='inline'; Codehighlighter1_326_397_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_326_397_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_326_397_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">nxt,NULL,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">nxt));<br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">end</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">count</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;solve(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;s,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;left,node&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">p)<br></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img id=Codehighlighter1_436_996_Open_Image onclick="this.style.display='none'; Codehighlighter1_436_996_Open_Text.style.display='none'; Codehighlighter1_436_996_Closed_Image.style.display='inline'; Codehighlighter1_436_996_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_436_996_Closed_Image onclick="this.style.display='none'; Codehighlighter1_436_996_Closed_Text.style.display='none'; Codehighlighter1_436_996_Open_Image.style.display='inline'; Codehighlighter1_436_996_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_436_996_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_436_996_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(count</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">z</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">end)&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(s</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">len</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">left</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">32</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&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">(left</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">33</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">count</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">35</span><span style="COLOR: #000000"><img id=Codehighlighter1_576_694_Open_Image onclick="this.style.display='none'; Codehighlighter1_576_694_Open_Text.style.display='none'; Codehighlighter1_576_694_Closed_Image.style.display='inline'; Codehighlighter1_576_694_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_576_694_Closed_Image onclick="this.style.display='none'; Codehighlighter1_576_694_Closed_Text.style.display='none'; Codehighlighter1_576_694_Open_Image.style.display='inline'; Codehighlighter1_576_694_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_576_694_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_576_694_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">36</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">end</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">37</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(solve(s,left</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,head))&nbsp;<br></span><span style="COLOR: #008080">38</span><span style="COLOR: #000000"><img id=Codehighlighter1_627_673_Open_Image onclick="this.style.display='none'; Codehighlighter1_627_673_Open_Text.style.display='none'; Codehighlighter1_627_673_Closed_Image.style.display='inline'; Codehighlighter1_627_673_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_627_673_Closed_Image onclick="this.style.display='none'; Codehighlighter1_627_673_Closed_Text.style.display='none'; Codehighlighter1_627_673_Open_Image.style.display='inline'; Codehighlighter1_627_673_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_627_673_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_627_673_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">39</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[z</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">left</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">s;<br></span><span style="COLOR: #008080">40</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">41</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">42</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">end</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">43</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">44</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(s</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">len)<br></span><span style="COLOR: #008080">45</span><span style="COLOR: #000000"><img id=Codehighlighter1_711_747_Open_Image onclick="this.style.display='none'; Codehighlighter1_711_747_Open_Text.style.display='none'; Codehighlighter1_711_747_Closed_Image.style.display='inline'; Codehighlighter1_711_747_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_711_747_Closed_Image onclick="this.style.display='none'; Codehighlighter1_711_747_Closed_Text.style.display='none'; Codehighlighter1_711_747_Open_Image.style.display='inline'; Codehighlighter1_711_747_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_711_747_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_711_747_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">46</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">count</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">47</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">48</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">49</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">count</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)&nbsp;count</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">;<br></span><span style="COLOR: #008080">50</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">nxt[str[s]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">48</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">NULL)<br></span><span style="COLOR: #008080">51</span><span style="COLOR: #000000"><img id=Codehighlighter1_811_879_Open_Image onclick="this.style.display='none'; Codehighlighter1_811_879_Open_Text.style.display='none'; Codehighlighter1_811_879_Closed_Image.style.display='inline'; Codehighlighter1_811_879_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_811_879_Closed_Image onclick="this.style.display='none'; Codehighlighter1_811_879_Closed_Text.style.display='none'; Codehighlighter1_811_879_Open_Image.style.display='inline'; Codehighlighter1_811_879_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_811_879_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_811_879_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">52</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">nxt[str[s]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">48</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=&amp;</span><span style="COLOR: #000000">buffer[c</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">53</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clear(p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">nxt[str[s]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">48</span><span style="COLOR: #000000">]);<br></span><span style="COLOR: #008080">54</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">55</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(solve(s</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,left,p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">nxt[str[s]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">48</span><span style="COLOR: #000000">]))&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">56</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">count</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)&nbsp;count</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">;<br></span><span style="COLOR: #008080">57</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">count</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">58</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">59</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">60</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br></span><span style="COLOR: #008080">61</span><span style="COLOR: #000000"><img id=Codehighlighter1_1011_1360_Open_Image onclick="this.style.display='none'; Codehighlighter1_1011_1360_Open_Text.style.display='none'; Codehighlighter1_1011_1360_Closed_Image.style.display='inline'; Codehighlighter1_1011_1360_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1011_1360_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1011_1360_Closed_Text.style.display='none'; Codehighlighter1_1011_1360_Open_Image.style.display='inline'; Codehighlighter1_1011_1360_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1011_1360_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1011_1360_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">62</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;test;<br></span><span style="COLOR: #008080">63</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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">test);<br></span><span style="COLOR: #008080">64</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(test</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">65</span><span style="COLOR: #000000"><img id=Codehighlighter1_1064_1345_Open_Image onclick="this.style.display='none'; Codehighlighter1_1064_1345_Open_Text.style.display='none'; Codehighlighter1_1064_1345_Closed_Image.style.display='inline'; Codehighlighter1_1064_1345_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1064_1345_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1064_1345_Closed_Text.style.display='none'; Codehighlighter1_1064_1345_Open_Image.style.display='inline'; Codehighlighter1_1064_1345_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1064_1345_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1064_1345_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">66</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">67</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">68</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;head</span><span style="COLOR: #000000">=&amp;</span><span style="COLOR: #000000">buffer[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">69</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clear(head);<br></span><span style="COLOR: #008080">70</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d%d%s</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">z,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">n,str);<br></span><span style="COLOR: #008080">71</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;len</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">strlen(str);<br></span><span style="COLOR: #008080">72</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;solve(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,z,head);<br></span><span style="COLOR: #008080">73</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">74</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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">z;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">75</span><span style="COLOR: #000000"><img id=Codehighlighter1_1232_1341_Open_Image onclick="this.style.display='none'; Codehighlighter1_1232_1341_Open_Text.style.display='none'; Codehighlighter1_1232_1341_Closed_Image.style.display='inline'; Codehighlighter1_1232_1341_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1232_1341_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1232_1341_Closed_Text.style.display='none'; Codehighlighter1_1232_1341_Open_Image.style.display='inline'; Codehighlighter1_1232_1341_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1232_1341_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1232_1341_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">76</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d-&gt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,i);<br></span><span style="COLOR: #008080">77</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">ans[i];j</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">ans[i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">78</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%c</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,str[j]);<br></span><span style="COLOR: #008080">79</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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></span><span style="COLOR: #008080">80</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">81</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">82</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">83</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></div>
<img src ="http://www.cppblog.com/yzhw/aggbug/138368.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-01-11 23:08 <a href="http://www.cppblog.com/yzhw/archive/2011/01/11/138368.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku1211 Traffic Lights 简单模拟+堆优化</title><link>http://www.cppblog.com/yzhw/archive/2011/01/09/138210.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Sun, 09 Jan 2011 12:22:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/01/09/138210.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/138210.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/01/09/138210.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/138210.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/138210.html</trackback:ping><description><![CDATA[题目说的很乱，我整理一下<br>所有灯都按绿、橙、红的顺序变化，绿色持续t-5秒，橙色持续5秒，红色持续t秒，第0时刻所有灯都是刚刚变绿。求所有灯再一次变绿的最早时刻<br><br>解法：<br>有一点要明确，所求的最早时刻肯定是所有灯中其中一盏刚刚变绿，否则我们能够找到一个更早的时刻所有灯都是绿的。那么只要枚举所有灯的开始时间，然后再判断此时刻所有灯都是绿色即可。<br>由于题目要求时刻小于5小时，即使暴力枚举也不过3600*5，再加上判断复杂度，总复杂度为360000*5，应该也能过<br>当然，可以用堆来优化，这样能够将最坏复杂度至少降低一半<br><br>代码：<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstdio</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">queue</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstring</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></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: #008080">&nbsp;5</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;node<br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img id=Codehighlighter1_90_214_Open_Image onclick="this.style.display='none'; Codehighlighter1_90_214_Open_Text.style.display='none'; Codehighlighter1_90_214_Closed_Image.style.display='inline'; Codehighlighter1_90_214_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_90_214_Closed_Image onclick="this.style.display='none'; Codehighlighter1_90_214_Closed_Text.style.display='none'; Codehighlighter1_90_214_Open_Image.style.display='inline'; Codehighlighter1_90_214_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_90_214_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_90_214_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,t;<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;node&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">b)&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img id=Codehighlighter1_146_171_Open_Image onclick="this.style.display='none'; Codehighlighter1_146_171_Open_Text.style.display='none'; Codehighlighter1_146_171_Closed_Image.style.display='inline'; Codehighlighter1_146_171_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_146_171_Closed_Image onclick="this.style.display='none'; Codehighlighter1_146_171_Closed_Text.style.display='none'; Codehighlighter1_146_171_Open_Image.style.display='inline'; Codehighlighter1_146_171_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_146_171_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_146_171_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;t</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">b.t;<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img id=Codehighlighter1_211_212_Open_Image onclick="this.style.display='none'; Codehighlighter1_211_212_Open_Text.style.display='none'; Codehighlighter1_211_212_Closed_Image.style.display='inline'; Codehighlighter1_211_212_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_211_212_Closed_Image onclick="this.style.display='none'; Codehighlighter1_211_212_Closed_Text.style.display='none'; Codehighlighter1_211_212_Open_Image.style.display='inline'; Codehighlighter1_211_212_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;node(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;id,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;time):i(id),t(time)</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_211_212_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_211_212_Open_Text><span style="COLOR: #000000">{}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;loop[</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">],c,start;<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">priority_queue</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">node</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;q;<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;chk(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;t)<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img id=Codehighlighter1_280_371_Open_Image onclick="this.style.display='none'; Codehighlighter1_280_371_Open_Text.style.display='none'; Codehighlighter1_280_371_Closed_Image.style.display='inline'; Codehighlighter1_280_371_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_280_371_Closed_Image onclick="this.style.display='none'; Codehighlighter1_280_371_Closed_Text.style.display='none'; Codehighlighter1_280_371_Open_Image.style.display='inline'; Codehighlighter1_280_371_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_280_371_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_280_371_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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">c;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(t</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">loop[i])</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">loop[i]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;&nbsp;<br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;print(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;t)<br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img id=Codehighlighter1_391_518_Open_Image onclick="this.style.display='none'; Codehighlighter1_391_518_Open_Text.style.display='none'; Codehighlighter1_391_518_Closed_Image.style.display='inline'; Codehighlighter1_391_518_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_391_518_Closed_Image onclick="this.style.display='none'; Codehighlighter1_391_518_Closed_Text.style.display='none'; Codehighlighter1_391_518_Open_Image.style.display='inline'; Codehighlighter1_391_518_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_391_518_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_391_518_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s%d:%s%d:%s%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,t</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">3600</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">,t</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">3600</span><span style="COLOR: #000000">,(t</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">3600</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">60</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">,(t</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">3600</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">60</span><span style="COLOR: #000000">,(t</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">3600</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">60</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">,(t</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">3600</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">60</span><span style="COLOR: #000000">);&nbsp;<br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img id=Codehighlighter1_531_1490_Open_Image onclick="this.style.display='none'; Codehighlighter1_531_1490_Open_Text.style.display='none'; Codehighlighter1_531_1490_Closed_Image.style.display='inline'; Codehighlighter1_531_1490_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_531_1490_Closed_Image onclick="this.style.display='none'; Codehighlighter1_531_1490_Closed_Text.style.display='none'; Codehighlighter1_531_1490_Open_Image.style.display='inline'; Codehighlighter1_531_1490_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_531_1490_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_531_1490_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img id=Codehighlighter1_551_1472_Open_Image onclick="this.style.display='none'; Codehighlighter1_551_1472_Open_Text.style.display='none'; Codehighlighter1_551_1472_Closed_Image.style.display='inline'; Codehighlighter1_551_1472_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_551_1472_Closed_Image onclick="this.style.display='none'; Codehighlighter1_551_1472_Closed_Text.style.display='none'; Codehighlighter1_551_1472_Open_Image.style.display='inline'; Codehighlighter1_551_1472_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_551_1472_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_551_1472_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">q.empty())&nbsp;q.pop();<br></span><span style="COLOR: #008080">32</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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">loop[c</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]);<br></span><span style="COLOR: #008080">33</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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">loop[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">])<br></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img id=Codehighlighter1_652_716_Open_Image onclick="this.style.display='none'; Codehighlighter1_652_716_Open_Text.style.display='none'; Codehighlighter1_652_716_Closed_Image.style.display='inline'; Codehighlighter1_652_716_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_652_716_Closed_Image onclick="this.style.display='none'; Codehighlighter1_652_716_Closed_Text.style.display='none'; Codehighlighter1_652_716_Open_Image.style.display='inline'; Codehighlighter1_652_716_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_652_716_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_652_716_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">35</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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">loop[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">loop[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]);<br></span><span style="COLOR: #008080">36</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">37</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">38</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">39</span><span style="COLOR: #000000"><img id=Codehighlighter1_735_1467_Open_Image onclick="this.style.display='none'; Codehighlighter1_735_1467_Open_Text.style.display='none'; Codehighlighter1_735_1467_Closed_Image.style.display='inline'; Codehighlighter1_735_1467_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_735_1467_Closed_Image onclick="this.style.display='none'; Codehighlighter1_735_1467_Closed_Text.style.display='none'; Codehighlighter1_735_1467_Open_Image.style.display='inline'; Codehighlighter1_735_1467_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_735_1467_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_735_1467_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">40</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">41</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(loop[c</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])<br></span><span style="COLOR: #008080">42</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&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">loop[c</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]);<br></span><span style="COLOR: #008080">43</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">44</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0xfffffff</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">45</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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">c;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">46</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(loop[i]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">start)&nbsp;start</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">loop[i]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">47</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">48</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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">c;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">49</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">loop[i]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">start</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">3600</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">)&nbsp;q.push(node(i,</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">loop[i]));<br></span><span style="COLOR: #008080">50</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">q.empty()</span><span style="COLOR: #000000">&amp;&amp;!</span><span style="COLOR: #000000">flag)<br></span><span style="COLOR: #008080">51</span><span style="COLOR: #000000"><img id=Codehighlighter1_1107_1353_Open_Image onclick="this.style.display='none'; Codehighlighter1_1107_1353_Open_Text.style.display='none'; Codehighlighter1_1107_1353_Closed_Image.style.display='inline'; Codehighlighter1_1107_1353_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1107_1353_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1107_1353_Closed_Text.style.display='none'; Codehighlighter1_1107_1353_Open_Image.style.display='inline'; Codehighlighter1_1107_1353_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1107_1353_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1107_1353_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">52</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;node&nbsp;top</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">q.top();<br></span><span style="COLOR: #008080">53</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q.pop();<br></span><span style="COLOR: #008080">54</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(chk(top.t))&nbsp;flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">top.t;<br></span><span style="COLOR: #008080">55</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">56</span><span style="COLOR: #000000"><img id=Codehighlighter1_1233_1341_Open_Image onclick="this.style.display='none'; Codehighlighter1_1233_1341_Open_Text.style.display='none'; Codehighlighter1_1233_1341_Closed_Image.style.display='inline'; Codehighlighter1_1233_1341_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1233_1341_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1233_1341_Closed_Text.style.display='none'; Codehighlighter1_1233_1341_Open_Image.style.display='inline'; Codehighlighter1_1233_1341_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1233_1341_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1233_1341_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">57</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;top.t</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">loop[top.i];<br></span><span style="COLOR: #008080">58</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(top.t</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">start</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">3600</span><span style="COLOR: #000000">)&nbsp;q.push(top);<br></span><span style="COLOR: #008080">59</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">60</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">61</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(flag)&nbsp;print(flag</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">start);<br></span><span style="COLOR: #008080">62</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Signals&nbsp;fail&nbsp;to&nbsp;synchronise&nbsp;in&nbsp;5&nbsp;hours\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">63</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">64</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">65</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">66</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">67</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br></span><span style="COLOR: #008080">68</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
<img src ="http://www.cppblog.com/yzhw/aggbug/138210.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-01-09 20:22 <a href="http://www.cppblog.com/yzhw/archive/2011/01/09/138210.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PKU1240 Pre-Post-erous! 基于树的遍历概念的题目</title><link>http://www.cppblog.com/yzhw/archive/2011/01/08/138160.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Sat, 08 Jan 2011 10:50:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/01/08/138160.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/138160.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/01/08/138160.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/138160.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/138160.html</trackback:ping><description><![CDATA[题意：<br>给出一棵K叉树的前序和后序遍历，问中序遍历有多少种<br><br>解法：<br>之所以中序遍历会有多种，原因是存在不满儿子的节点，导致树的形态有不同<br>通过前序和后序遍历，可以将每一棵子树划分出来，然后递归的累乘计算个数（乘法原理），最后再乘以C<sub>k</sub><sup>n</sup>，n为当前节点的子树个数<br><br>代码：<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstdio</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></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: #008080">&nbsp;3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstdlib</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstring</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;pre[</span><span style="COLOR: #000000">50</span><span style="COLOR: #000000">],post[</span><span style="COLOR: #000000">50</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;c[</span><span style="COLOR: #000000">21</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">21</span><span style="COLOR: #000000">],k;<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;solve(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;s1,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;s2,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;l)<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img id=Codehighlighter1_151_355_Open_Image onclick="this.style.display='none'; Codehighlighter1_151_355_Open_Text.style.display='none'; Codehighlighter1_151_355_Closed_Image.style.display='inline'; Codehighlighter1_151_355_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_151_355_Closed_Image onclick="this.style.display='none'; Codehighlighter1_151_355_Closed_Text.style.display='none'; Codehighlighter1_151_355_Open_Image.style.display='inline'; Codehighlighter1_151_355_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_151_355_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_151_355_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;ans</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,co</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,last;<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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">s1</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">s1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">l;i</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">s2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">last)<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img id=Codehighlighter1_220_328_Open_Image onclick="this.style.display='none'; Codehighlighter1_220_328_Open_Text.style.display='none'; Codehighlighter1_220_328_Closed_Image.style.display='inline'; Codehighlighter1_220_328_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_220_328_Closed_Image onclick="this.style.display='none'; Codehighlighter1_220_328_Closed_Text.style.display='none'; Codehighlighter1_220_328_Open_Image.style.display='inline'; Codehighlighter1_220_328_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_220_328_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_220_328_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;last</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">s2;<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;co</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(;post[s2]</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">pre[i];s2</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans</span><span style="COLOR: #000000">*=</span><span style="COLOR: #000000">solve(i,last,</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">s2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">last);<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;ans</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">c[k][co];<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img id=Codehighlighter1_368_639_Open_Image onclick="this.style.display='none'; Codehighlighter1_368_639_Open_Text.style.display='none'; Codehighlighter1_368_639_Closed_Image.style.display='inline'; Codehighlighter1_368_639_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_368_639_Closed_Image onclick="this.style.display='none'; Codehighlighter1_368_639_Closed_Text.style.display='none'; Codehighlighter1_368_639_Open_Image.style.display='inline'; Codehighlighter1_368_639_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_368_639_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_368_639_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;memset(c,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(c));<br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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">20</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;c[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">c[i][i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">20</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&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;j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">i;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">c[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">c[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j];<br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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%s%s</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">k,pre,post)</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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">,solve(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,strlen(pre)));<br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
<img src ="http://www.cppblog.com/yzhw/aggbug/138160.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-01-08 18:50 <a href="http://www.cppblog.com/yzhw/archive/2011/01/08/138160.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku 3306 Busy Airport 模拟+堆</title><link>http://www.cppblog.com/yzhw/archive/2011/01/06/138047.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Wed, 05 Jan 2011 19:22:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/01/06/138047.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/138047.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/01/06/138047.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/138047.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/138047.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 题意就不说了，就是模拟一个机场的起降时间如果当前时刻不能起飞，则推迟10分钟再次尝试这题里面还包含一个历法子问题，甚是麻烦。。于是就用了各种C++面向对象技术把条理理清楚历法的详细解释在题目最底端，不是我们用的公历直接贴代码了Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighli...&nbsp;&nbsp;<a href='http://www.cppblog.com/yzhw/archive/2011/01/06/138047.html'>阅读全文</a><img src ="http://www.cppblog.com/yzhw/aggbug/138047.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-01-06 03:22 <a href="http://www.cppblog.com/yzhw/archive/2011/01/06/138047.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku2525 Text Formalization 恶心的模拟</title><link>http://www.cppblog.com/yzhw/archive/2011/01/04/137982.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Tue, 04 Jan 2011 15:36:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2011/01/04/137982.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/137982.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2011/01/04/137982.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/137982.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/137982.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 题意是这样：将一篇文章中的缩写和简略语替换成原来的样子。有点要求，缩写只在第一次替换。如果有多种替换方法，则最先出现的可替换词优先替换。如果还有重复，则列表前面的先替换。解法：狂用string.h里的函数然后+暴力就可以了，这种模拟题一般不会考到什么算法。。代码：Code highlighting produced by Actipro CodeHighlighter (freeware)ht...&nbsp;&nbsp;<a href='http://www.cppblog.com/yzhw/archive/2011/01/04/137982.html'>阅读全文</a><img src ="http://www.cppblog.com/yzhw/aggbug/137982.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2011-01-04 23:36 <a href="http://www.cppblog.com/yzhw/archive/2011/01/04/137982.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku 1262 input 离散化</title><link>http://www.cppblog.com/yzhw/archive/2010/12/10/136071.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Fri, 10 Dec 2010 08:52:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2010/12/10/136071.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/136071.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2010/12/10/136071.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/136071.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/136071.html</trackback:ping><description><![CDATA[<meta http-equiv="content-type" content="text/html; charset=utf-8">题意：<br>给出一些瓷砖，以及需要铺的面积w*h（从(0,0)到(w,h)），求：<br>（1）这些瓷砖是否有重叠<br>（2）这些瓷砖是否超过了地面的边界<br>（3）这些瓷砖能否完整的铺盖地面<br>瓷砖个数n&lt;100<br>解法：<br>对于第一问，传统的做法应该是离散化+线段树。但是此题数据量很小，n&lt;100离散化后面积不过160000，可以暴力判重。<br>对于第二问，扫描一遍即可<br>对于第三问，计算下总面积即可。<br>代码：<br><div style="padding-right: 5px; padding-left: 4px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); padding-bottom: 4px; border-left-color: rgb(204, 204, 204); padding-top: 4px; font-size: 13px; width: 1090px; word-break: break-all; "><span style="color: rgb(0, 128, 128); ">&nbsp;1</span>&nbsp;<span style="color: rgb(0, 0, 0); ">#&nbsp;include&nbsp;</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 0); ">cstdio</span><span style="color: rgb(0, 0, 0); ">&gt;</span><span style="color: rgb(0, 0, 0); "><br></span><span style="color: rgb(0, 128, 128); ">&nbsp;2</span>&nbsp;<span style="color: rgb(0, 0, 0); "></span><span style="color: rgb(0, 0, 255); ">using</span><span style="color: rgb(0, 0, 0); ">&nbsp;</span><span style="color: rgb(0, 0, 255); ">namespace</span><span style="color: rgb(0, 0, 0); ">&nbsp;std;<br></span><span style="color: rgb(0, 128, 128); ">&nbsp;3</span>&nbsp;<span style="color: rgb(0, 0, 0); ">#&nbsp;include&nbsp;</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 0); ">vector</span><span style="color: rgb(0, 0, 0); ">&gt;</span><span style="color: rgb(0, 0, 0); "><br></span><span style="color: rgb(0, 128, 128); ">&nbsp;4</span>&nbsp;<span style="color: rgb(0, 0, 0); ">#&nbsp;include&nbsp;</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 0); ">algorithm</span><span style="color: rgb(0, 0, 0); ">&gt;</span><span style="color: rgb(0, 0, 0); "><br></span><span style="color: rgb(0, 128, 128); ">&nbsp;5</span>&nbsp;<span style="color: rgb(0, 0, 0); ">#&nbsp;include&nbsp;</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 0); ">cstring</span><span style="color: rgb(0, 0, 0); ">&gt;</span><span style="color: rgb(0, 0, 0); "><br></span><span style="color: rgb(0, 128, 128); ">&nbsp;6</span>&nbsp;<span style="color: rgb(0, 0, 0); "></span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;data[</span><span style="color: rgb(0, 0, 0); ">101</span><span style="color: rgb(0, 0, 0); ">][</span><span style="color: rgb(0, 0, 0); ">4</span><span style="color: rgb(0, 0, 0); ">],c1,tmp1[</span><span style="color: rgb(0, 0, 0); ">500</span><span style="color: rgb(0, 0, 0); ">],c2,tmp2[</span><span style="color: rgb(0, 0, 0); ">500</span><span style="color: rgb(0, 0, 0); ">],n,w,h;<br></span><span style="color: rgb(0, 128, 128); ">&nbsp;7</span>&nbsp;<span style="color: rgb(0, 0, 0); "></span><span style="color: rgb(0, 0, 255); ">bool</span><span style="color: rgb(0, 0, 0); ">&nbsp;used[</span><span style="color: rgb(0, 0, 0); ">500</span><span style="color: rgb(0, 0, 0); ">][</span><span style="color: rgb(0, 0, 0); ">500</span><span style="color: rgb(0, 0, 0); ">];<br></span><span style="color: rgb(0, 128, 128); ">&nbsp;8</span>&nbsp;<span style="color: rgb(0, 0, 0); "></span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;main()<br></span><span style="color: rgb(0, 128, 128); ">&nbsp;9</span>&nbsp;<span style="color: rgb(0, 0, 0); ">{<br></span><span style="color: rgb(0, 128, 128); ">10</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;test;<br></span><span style="color: rgb(0, 128, 128); ">11</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: rgb(0, 0, 0); ">"</span><span style="color: rgb(0, 0, 0); ">%d</span><span style="color: rgb(0, 0, 0); ">"</span><span style="color: rgb(0, 0, 0); ">,</span><span style="color: rgb(0, 0, 0); ">&amp;</span><span style="color: rgb(0, 0, 0); ">test);<br></span><span style="color: rgb(0, 128, 128); ">12</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">while</span><span style="color: rgb(0, 0, 0); ">(test</span><span style="color: rgb(0, 0, 0); ">--</span><span style="color: rgb(0, 0, 0); ">)<br></span><span style="color: rgb(0, 128, 128); ">13</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: rgb(0, 128, 128); ">14</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;total</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">;<br></span><span style="color: rgb(0, 128, 128); ">15</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: rgb(0, 0, 0); ">"</span><span style="color: rgb(0, 0, 0); ">%d%d%d</span><span style="color: rgb(0, 0, 0); ">"</span><span style="color: rgb(0, 0, 0); ">,</span><span style="color: rgb(0, 0, 0); ">&amp;</span><span style="color: rgb(0, 0, 0); ">w,</span><span style="color: rgb(0, 0, 0); ">&amp;</span><span style="color: rgb(0, 0, 0); ">h,</span><span style="color: rgb(0, 0, 0); ">&amp;</span><span style="color: rgb(0, 0, 0); ">n);<br></span><span style="color: rgb(0, 128, 128); ">16</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c1</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">c2</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">;<br></span><span style="color: rgb(0, 128, 128); ">17</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(used,</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">,</span><span style="color: rgb(0, 0, 255); ">sizeof</span><span style="color: rgb(0, 0, 0); ">(used));<br></span><span style="color: rgb(0, 128, 128); ">18</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">for</span><span style="color: rgb(0, 0, 0); ">(</span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;i</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">;i</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 0); ">n;i</span><span style="color: rgb(0, 0, 0); ">++</span><span style="color: rgb(0, 0, 0); ">)<br></span><span style="color: rgb(0, 128, 128); ">19</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: rgb(0, 128, 128); ">20</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: rgb(0, 0, 0); ">"</span><span style="color: rgb(0, 0, 0); ">%d%d%d%d</span><span style="color: rgb(0, 0, 0); ">"</span><span style="color: rgb(0, 0, 0); ">,</span><span style="color: rgb(0, 0, 0); ">&amp;</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">],</span><span style="color: rgb(0, 0, 0); ">&amp;</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">1</span><span style="color: rgb(0, 0, 0); ">],</span><span style="color: rgb(0, 0, 0); ">&amp;</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">2</span><span style="color: rgb(0, 0, 0); ">],</span><span style="color: rgb(0, 0, 0); ">&amp;</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">3</span><span style="color: rgb(0, 0, 0); ">]);<br></span><span style="color: rgb(0, 128, 128); ">21</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp1[c1</span><span style="color: rgb(0, 0, 0); ">++</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">];<br></span><span style="color: rgb(0, 128, 128); ">22</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp1[c1</span><span style="color: rgb(0, 0, 0); ">++</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">2</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 0); ">1</span><span style="color: rgb(0, 0, 0); ">;<br></span><span style="color: rgb(0, 128, 128); ">23</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp2[c2</span><span style="color: rgb(0, 0, 0); ">++</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">1</span><span style="color: rgb(0, 0, 0); ">];<br></span><span style="color: rgb(0, 128, 128); ">24</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp2[c2</span><span style="color: rgb(0, 0, 0); ">++</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">3</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 0); ">1</span><span style="color: rgb(0, 0, 0); ">;<br></span><span style="color: rgb(0, 128, 128); ">25</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: rgb(0, 128, 128); ">26</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort(tmp1,tmp1</span><span style="color: rgb(0, 0, 0); ">+</span><span style="color: rgb(0, 0, 0); ">c1);<br></span><span style="color: rgb(0, 128, 128); ">27</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c1</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">unique(tmp1,tmp1</span><span style="color: rgb(0, 0, 0); ">+</span><span style="color: rgb(0, 0, 0); ">c1)</span><span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 0); ">tmp1;<br></span><span style="color: rgb(0, 128, 128); ">28</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort(tmp2,tmp2</span><span style="color: rgb(0, 0, 0); ">+</span><span style="color: rgb(0, 0, 0); ">c2);<br></span><span style="color: rgb(0, 128, 128); ">29</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c2</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">unique(tmp2,tmp2</span><span style="color: rgb(0, 0, 0); ">+</span><span style="color: rgb(0, 0, 0); ">c2)</span><span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 0); ">tmp2;<br></span><span style="color: rgb(0, 128, 128); ">30</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">for</span><span style="color: rgb(0, 0, 0); ">(</span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;i</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">;i</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 0); ">n;i</span><span style="color: rgb(0, 0, 0); ">++</span><span style="color: rgb(0, 0, 0); ">)<br></span><span style="color: rgb(0, 128, 128); ">31</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: rgb(0, 128, 128); ">32</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;xl</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">lower_bound(tmp1,tmp1</span><span style="color: rgb(0, 0, 0); ">+</span><span style="color: rgb(0, 0, 0); ">c1,data[i][</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">])</span><span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 0); ">tmp1,xh</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">lower_bound(tmp1,tmp1</span><span style="color: rgb(0, 0, 0); ">+</span><span style="color: rgb(0, 0, 0); ">c1,data[i][</span><span style="color: rgb(0, 0, 0); ">2</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 0); ">1</span><span style="color: rgb(0, 0, 0); ">)</span><span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 0); ">tmp1;<br></span><span style="color: rgb(0, 128, 128); ">33</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;yl</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">lower_bound(tmp2,tmp2</span><span style="color: rgb(0, 0, 0); ">+</span><span style="color: rgb(0, 0, 0); ">c2,data[i][</span><span style="color: rgb(0, 0, 0); ">1</span><span style="color: rgb(0, 0, 0); ">])</span><span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 0); ">tmp2,yh</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">lower_bound(tmp2,tmp2</span><span style="color: rgb(0, 0, 0); ">+</span><span style="color: rgb(0, 0, 0); ">c2,data[i][</span><span style="color: rgb(0, 0, 0); ">3</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 0); ">1</span><span style="color: rgb(0, 0, 0); ">)</span><span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 0); ">tmp2;<br></span><span style="color: rgb(0, 128, 128); ">34</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">for</span><span style="color: rgb(0, 0, 0); ">(</span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;j</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">xl;j</span><span style="color: rgb(0, 0, 0); ">&lt;=</span><span style="color: rgb(0, 0, 0); ">xh;j</span><span style="color: rgb(0, 0, 0); ">++</span><span style="color: rgb(0, 0, 0); ">)<br></span><span style="color: rgb(0, 128, 128); ">35</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">for</span><span style="color: rgb(0, 0, 0); ">(</span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;k</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">yl;k</span><span style="color: rgb(0, 0, 0); ">&lt;=</span><span style="color: rgb(0, 0, 0); ">yh;k</span><span style="color: rgb(0, 0, 0); ">++</span><span style="color: rgb(0, 0, 0); ">)<br></span><span style="color: rgb(0, 128, 128); ">36</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">if</span><span style="color: rgb(0, 0, 0); ">(used[j][k])<br></span><span style="color: rgb(0, 128, 128); ">37</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: rgb(0, 128, 128); ">38</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0, 0, 0); ">"</span><span style="color: rgb(0, 0, 0); ">NONDISJOINT\n</span><span style="color: rgb(0, 0, 0); ">"</span><span style="color: rgb(0, 0, 0); ">);<br></span><span style="color: rgb(0, 128, 128); ">39</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&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><span style="color: rgb(0, 0, 255); ">goto</span><span style="color: rgb(0, 0, 0); ">&nbsp;end;<br></span><span style="color: rgb(0, 128, 128); ">40</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: rgb(0, 128, 128); ">41</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">else</span><span style="color: rgb(0, 0, 0); ">&nbsp;used[j][k]</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 255); ">true</span><span style="color: rgb(0, 0, 0); ">;<br></span><span style="color: rgb(0, 128, 128); ">42</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: rgb(0, 128, 128); ">43</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">for</span><span style="color: rgb(0, 0, 0); ">(</span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;i</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">;i</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 0); ">n;i</span><span style="color: rgb(0, 0, 0); ">++</span><span style="color: rgb(0, 0, 0); ">)<br></span><span style="color: rgb(0, 128, 128); ">44</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">if</span><span style="color: rgb(0, 0, 0); ">(data[i][</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">||</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">&gt;</span><span style="color: rgb(0, 0, 0); ">w</span><span style="color: rgb(0, 0, 0); ">||</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">2</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">||</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">2</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">&gt;</span><span style="color: rgb(0, 0, 0); ">w</span><span style="color: rgb(0, 0, 0); ">||</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">1</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">||</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">1</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">&gt;</span><span style="color: rgb(0, 0, 0); ">h</span><span style="color: rgb(0, 0, 0); ">||</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">3</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">||</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">3</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">&gt;</span><span style="color: rgb(0, 0, 0); ">h)<br></span><span style="color: rgb(0, 128, 128); ">45</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: rgb(0, 128, 128); ">46</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: rgb(0, 0, 0); ">"</span><span style="color: rgb(0, 0, 0); ">NONCONTAINED\n</span><span style="color: rgb(0, 0, 0); ">"</span><span style="color: rgb(0, 0, 0); ">);<br></span><span style="color: rgb(0, 128, 128); ">47</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">goto</span><span style="color: rgb(0, 0, 0); ">&nbsp;end;<br></span><span style="color: rgb(0, 128, 128); ">48</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: rgb(0, 128, 128); ">49</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">for</span><span style="color: rgb(0, 0, 0); ">(</span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;i</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">;i</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 0); ">n;i</span><span style="color: rgb(0, 0, 0); ">++</span><span style="color: rgb(0, 0, 0); ">)<br></span><span style="color: rgb(0, 128, 128); ">50</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;total</span><span style="color: rgb(0, 0, 0); ">+=</span><span style="color: rgb(0, 0, 0); ">(data[i][</span><span style="color: rgb(0, 0, 0); ">2</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">])</span><span style="color: rgb(0, 0, 0); ">*</span><span style="color: rgb(0, 0, 0); ">(data[i][</span><span style="color: rgb(0, 0, 0); ">3</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 0); ">data[i][</span><span style="color: rgb(0, 0, 0); ">1</span><span style="color: rgb(0, 0, 0); ">]);<br></span><span style="color: rgb(0, 128, 128); ">51</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">if</span><span style="color: rgb(0, 0, 0); ">(total</span><span style="color: rgb(0, 0, 0); ">!=</span><span style="color: rgb(0, 0, 0); ">w</span><span style="color: rgb(0, 0, 0); ">*</span><span style="color: rgb(0, 0, 0); ">h)&nbsp;printf(</span><span style="color: rgb(0, 0, 0); ">"</span><span style="color: rgb(0, 0, 0); ">NONCOVERING\n</span><span style="color: rgb(0, 0, 0); ">"</span><span style="color: rgb(0, 0, 0); ">);<br></span><span style="color: rgb(0, 128, 128); ">52</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">else</span><span style="color: rgb(0, 0, 0); ">&nbsp;printf(</span><span style="color: rgb(0, 0, 0); ">"</span><span style="color: rgb(0, 0, 0); ">OK\n</span><span style="color: rgb(0, 0, 0); ">"</span><span style="color: rgb(0, 0, 0); ">);<br></span><span style="color: rgb(0, 128, 128); ">53</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end:;<br></span><span style="color: rgb(0, 128, 128); ">54</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: rgb(0, 128, 128); ">55</span>&nbsp;<span style="color: rgb(0, 0, 0); ">}<br></span><span style="color: rgb(0, 128, 128); ">56</span>&nbsp;</div>
<img src ="http://www.cppblog.com/yzhw/aggbug/136071.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2010-12-10 16:52 <a href="http://www.cppblog.com/yzhw/archive/2010/12/10/136071.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>fzu 2007 Selecting courses （The 35th ACM/ICPC Asia Regional Fuzhou Site）贪心+堆</title><link>http://www.cppblog.com/yzhw/archive/2010/12/07/135631.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Mon, 06 Dec 2010 16:09:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2010/12/07/135631.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/135631.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2010/12/07/135631.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/135631.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/135631.html</trackback:ping><description><![CDATA[题意：<br>给出一堆课，选课时间从s<sub>i</sub>到e<sub>i</sub>，每个学生可以从任意一个时刻开始选课，然后每隔5分钟选一次，如果在某个时刻t，存在某个课程i,s<sub>i</sub>&lt;t,e<sub>i</sub>&gt;t，那么可以选这门课。问最多可以选多少门课。<br>解法：<br>首先注意，选课时间是<span style="color: red;">开区间，（s,e）</span>，需要事先处理为<span style="color: red;">[s*2+1,e*2-1]</span><br>然后就可以枚举起点然后贪心，每次取覆盖当前时间点的右端点最小的那个区间（课程）来选。<br>具体实现方法可以先按照s排序，然后建立一个以e为关键字的<span style="color: red;">小根堆，动态统计，这样复杂度O(nlogn)</span><br>代码:<br>
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080;">&nbsp;1</span>&nbsp;<span style="color: #000000;">#&nbsp;include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">cstdio</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;2</span>&nbsp;<span style="color: #000000;">#&nbsp;include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">queue</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;3</span>&nbsp;<span style="color: #000000;">#&nbsp;include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">algorithm</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;4</span>&nbsp;<span style="color: #000000;">#&nbsp;include&nbsp;</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: #008080;">&nbsp;5</span>&nbsp;<span style="color: #000000;"></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: #008080;">&nbsp;6</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;n;<br></span><span style="color: #008080;">&nbsp;7</span>&nbsp;<span style="color: #000000;"></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;">305</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;8</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;node<br></span><span style="color: #008080;">&nbsp;9</span>&nbsp;<span style="color: #000000;">{<br></span><span style="color: #008080;">10</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;s,e;<br></span><span style="color: #008080;">11</span>&nbsp;<span style="color: #000000;">}data[N];<br></span><span style="color: #008080;">12</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">bool</span><span style="color: #000000;">&nbsp;cmp(</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;node&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">a,</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;node&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">b)<br></span><span style="color: #008080;">13</span>&nbsp;<span style="color: #000000;">{<br></span><span style="color: #008080;">14</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;a.s</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">b.s;<br></span><span style="color: #008080;">15</span>&nbsp;<span style="color: #000000;">}<br></span><span style="color: #008080;">16</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;cmp1<br></span><span style="color: #008080;">17</span>&nbsp;<span style="color: #000000;">{<br></span><span style="color: #008080;">18</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">bool</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">operator</span><span style="color: #000000;">()(</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;node&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">a,</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;node&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">b)&nbsp;</span><span style="color: #0000ff;">const</span><span style="color: #000000;"><br></span><span style="color: #008080;">19</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">20</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;a.e</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">b.e;<br></span><span style="color: #008080;">21</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;}&nbsp;<br></span><span style="color: #008080;">22</span>&nbsp;<span style="color: #000000;">};<br></span><span style="color: #008080;">23</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;main()<br></span><span style="color: #008080;">24</span>&nbsp;<span style="color: #000000;">{<br></span><span style="color: #008080;">25</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">(</span><span style="color: #0000ff;">true</span><span style="color: #000000;">)<br></span><span style="color: #008080;">26</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">27</span>&nbsp;<span style="color: #000000;">&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;">n);<br></span><span style="color: #008080;">28</span>&nbsp;<span style="color: #000000;">&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;">n)&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br></span><span style="color: #008080;">29</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;start</span><span style="color: #000000;">=</span><span style="color: #000000;">0xfffffff</span><span style="color: #000000;">,end</span><span style="color: #000000;">=-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br></span><span style="color: #008080;">30</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&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;">n;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">31</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">32</span>&nbsp;<span style="color: #000000;">&nbsp;&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;">data[i].s,</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">data[i].e);<br></span><span style="color: #008080;">33</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data[i].s</span><span style="color: #000000;">=</span><span style="color: #000000;">data[i].s</span><span style="color: #000000;">*</span><span style="color: #000000;">2</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br></span><span style="color: #008080;">34</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data[i].e</span><span style="color: #000000;">=</span><span style="color: #000000;">data[i].e</span><span style="color: #000000;">*</span><span style="color: #000000;">2</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br></span><span style="color: #008080;">35</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start</span><span style="color: #000000;">=</span><span style="color: #000000;">min(start,data[i].s);<br></span><span style="color: #008080;">36</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end</span><span style="color: #000000;">=</span><span style="color: #000000;">max(data[i].e,end);<br></span><span style="color: #008080;">37</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">38</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort(data,data</span><span style="color: #000000;">+</span><span style="color: #000000;">n,cmp);<br></span><span style="color: #008080;">39</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;res</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">40</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&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;s</span><span style="color: #000000;">=</span><span style="color: #000000;">start;s</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">start</span><span style="color: #000000;">+</span><span style="color: #000000;">10</span><span style="color: #000000;">;s</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">41</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">42</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;total</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">,p</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">43</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;priority_queue</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">node,vector</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">node</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">,cmp1</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;q;<br></span><span style="color: #008080;">44</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;t</span><span style="color: #000000;">=</span><span style="color: #000000;">s;t</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">end;t</span><span style="color: #000000;">+=</span><span style="color: #000000;">10</span><span style="color: #000000;">)<br></span><span style="color: #008080;">45</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">46</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">(p</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">n</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">data[p].s</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">t)<br></span><span style="color: #008080;">47</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q.push(data[p</span><span style="color: #000000;">++</span><span style="color: #000000;">]);<br></span><span style="color: #008080;">48</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">(</span><span style="color: #000000;">!</span><span style="color: #000000;">q.empty()</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">q.top().e</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">t)&nbsp;q.pop();<br></span><span style="color: #008080;">49</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;">q.empty())<br></span><span style="color: #008080;">50</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">51</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;total</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br></span><span style="color: #008080;">52</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q.pop();<br></span><span style="color: #008080;">53</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">54</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">55</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res</span><span style="color: #000000;">=</span><span style="color: #000000;">max(res,total);<br></span><span style="color: #008080;">56</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">57</span>&nbsp;<span style="color: #000000;">&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></span><span style="color: #008080;">58</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">59</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">60</span>&nbsp;<span style="color: #000000;">}<br></span><span style="color: #008080;">61</span>&nbsp;<span style="color: #000000;"></span></div>
<br><br> <img src ="http://www.cppblog.com/yzhw/aggbug/135631.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2010-12-07 00:09 <a href="http://www.cppblog.com/yzhw/archive/2010/12/07/135631.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku 3668 Game of Lines hash</title><link>http://www.cppblog.com/yzhw/archive/2010/12/05/135489.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Sat, 04 Dec 2010 17:26:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2010/12/05/135489.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/135489.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2010/12/05/135489.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/135489.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/135489.html</trackback:ping><description><![CDATA[<p>题意：<br>给出一些点，求出由这些点可以构成多少斜率不同的线段。<br>解法：<br>O（N<sup>2</sup>）枚举直线，然后hash记录斜率（要特别考虑斜率不存在的情况），注意浮点数的比较精度控制在1e-8或者用pair来通分比较。。<br>代码：<br></p>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">#&nbsp;include&nbsp;</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: #008080">&nbsp;2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cmath</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></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: #008080">&nbsp;4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;cmp<br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img id=Codehighlighter1_87_189_Open_Image onclick="this.style.display='none'; Codehighlighter1_87_189_Open_Text.style.display='none'; Codehighlighter1_87_189_Closed_Image.style.display='inline'; Codehighlighter1_87_189_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_87_189_Closed_Image onclick="this.style.display='none'; Codehighlighter1_87_189_Closed_Text.style.display='none'; Codehighlighter1_87_189_Open_Image.style.display='inline'; Codehighlighter1_87_189_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_87_189_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_87_189_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">()(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;a,</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;b)&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img id=Codehighlighter1_148_187_Open_Image onclick="this.style.display='none'; Codehighlighter1_148_187_Open_Text.style.display='none'; Codehighlighter1_148_187_Closed_Image.style.display='inline'; Codehighlighter1_148_187_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_148_187_Closed_Image onclick="this.style.display='none'; Codehighlighter1_148_187_Closed_Text.style.display='none'; Codehighlighter1_148_187_Open_Image.style.display='inline'; Codehighlighter1_148_187_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_148_187_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_148_187_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;fabs(a</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">b)</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">1e</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">b;<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">;&nbsp;<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">,cmp</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;refer;<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;sp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;data[</span><span style="COLOR: #000000">201</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img id=Codehighlighter1_256_582_Open_Image onclick="this.style.display='none'; Codehighlighter1_256_582_Open_Text.style.display='none'; Codehighlighter1_256_582_Closed_Image.style.display='inline'; Codehighlighter1_256_582_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_256_582_Closed_Image onclick="this.style.display='none'; Codehighlighter1_256_582_Closed_Text.style.display='none'; Codehighlighter1_256_582_Open_Image.style.display='inline'; Codehighlighter1_256_582_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_256_582_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_256_582_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n;<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img id=Codehighlighter1_306_513_Open_Image onclick="this.style.display='none'; Codehighlighter1_306_513_Open_Text.style.display='none'; Codehighlighter1_306_513_Closed_Image.style.display='inline'; Codehighlighter1_306_513_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_306_513_Closed_Image onclick="this.style.display='none'; Codehighlighter1_306_513_Closed_Text.style.display='none'; Codehighlighter1_306_513_Open_Image.style.display='inline'; Codehighlighter1_306_513_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_306_513_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_306_513_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">data[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">data[i][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&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;j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">i;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(data[j][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">data[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">])<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;refer.insert((data[j][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">data[i][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">)(data[j][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">data[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]));<br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">refer.size()</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">sp</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;system("pause");</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">30</span><span style="COLOR: #008000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">32</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
<img src ="http://www.cppblog.com/yzhw/aggbug/135489.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2010-12-05 01:26 <a href="http://www.cppblog.com/yzhw/archive/2010/12/05/135489.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku 3497 Assemble 二分+模拟+STL</title><link>http://www.cppblog.com/yzhw/archive/2010/12/02/135301.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Thu, 02 Dec 2010 14:42:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2010/12/02/135301.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/135301.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2010/12/02/135301.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/135301.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/135301.html</trackback:ping><description><![CDATA[<p>题意：<br>若干电脑配件，若干型号，每个型号都有价格和性能指数。求在K钱内的配置方案，使得最差性能最好。。<br>解法：<br>二分+判断<br>代码：<br></p>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstdio</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstring</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">map</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">algorithm</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#&nbsp;include&nbsp;</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: #008080">&nbsp;8</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></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: #008080">&nbsp;9</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;node<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img id=Codehighlighter1_164_252_Open_Image onclick="this.style.display='none'; Codehighlighter1_164_252_Open_Text.style.display='none'; Codehighlighter1_164_252_Closed_Image.style.display='inline'; Codehighlighter1_164_252_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_164_252_Closed_Image onclick="this.style.display='none'; Codehighlighter1_164_252_Closed_Text.style.display='none'; Codehighlighter1_164_252_Open_Image.style.display='inline'; Codehighlighter1_164_252_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_164_252_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_164_252_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&nbsp;name;<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;p,q;<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img id=Codehighlighter1_248_249_Open_Image onclick="this.style.display='none'; Codehighlighter1_248_249_Open_Text.style.display='none'; Codehighlighter1_248_249_Closed_Image.style.display='inline'; Codehighlighter1_248_249_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_248_249_Closed_Image onclick="this.style.display='none'; Codehighlighter1_248_249_Closed_Text.style.display='none'; Codehighlighter1_248_249_Open_Image.style.display='inline'; Codehighlighter1_248_249_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;node(</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&nbsp;na,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;pr,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;qu):name(na),p(pr),q(qu)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_248_249_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_248_249_Open_Text><span style="COLOR: #000000">{}</span></span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;cmp<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img id=Codehighlighter1_266_362_Open_Image onclick="this.style.display='none'; Codehighlighter1_266_362_Open_Text.style.display='none'; Codehighlighter1_266_362_Closed_Image.style.display='inline'; Codehighlighter1_266_362_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_266_362_Closed_Image onclick="this.style.display='none'; Codehighlighter1_266_362_Closed_Text.style.display='none'; Codehighlighter1_266_362_Open_Image.style.display='inline'; Codehighlighter1_266_362_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_266_362_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_266_362_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">()(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;node&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a,</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;node&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">b)&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img id=Codehighlighter1_325_360_Open_Image onclick="this.style.display='none'; Codehighlighter1_325_360_Open_Text.style.display='none'; Codehighlighter1_325_360_Closed_Image.style.display='inline'; Codehighlighter1_325_360_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_325_360_Closed_Image onclick="this.style.display='none'; Codehighlighter1_325_360_Closed_Text.style.display='none'; Codehighlighter1_325_360_Open_Image.style.display='inline'; Codehighlighter1_325_360_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_325_360_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_325_360_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;a.name</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">b.name;<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,m;<br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">map</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">,vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">node</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">data;<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;refer;<br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;chk(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;mid)<br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img id=Codehighlighter1_442_757_Open_Image onclick="this.style.display='none'; Codehighlighter1_442_757_Open_Text.style.display='none'; Codehighlighter1_442_757_Closed_Image.style.display='inline'; Codehighlighter1_442_757_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_442_757_Closed_Image onclick="this.style.display='none'; Codehighlighter1_442_757_Closed_Text.style.display='none'; Codehighlighter1_442_757_Open_Image.style.display='inline'; Codehighlighter1_442_757_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_442_757_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_442_757_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;total</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(map</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">,vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">node</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">::iterator&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">data.begin();i</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">data.end();i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img id=Codehighlighter1_546_724_Open_Image onclick="this.style.display='none'; Codehighlighter1_546_724_Open_Text.style.display='none'; Codehighlighter1_546_724_Closed_Image.style.display='inline'; Codehighlighter1_546_724_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_546_724_Closed_Image onclick="this.style.display='none'; Codehighlighter1_546_724_Closed_Text.style.display='none'; Codehighlighter1_546_724_Open_Image.style.display='inline'; Codehighlighter1_546_724_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_546_724_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_546_724_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;tp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0xfffffff</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">node</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">::iterator&nbsp;j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">second).begin();j</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">second).end();j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">32</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">q</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">mid</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">p</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">tp)<br></span><span style="COLOR: #008080">33</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">p;<br></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;total</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">tp;<br></span><span style="COLOR: #008080">35</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">36</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;total</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">)m;<br></span><span style="COLOR: #008080">37</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">38</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br></span><span style="COLOR: #008080">39</span><span style="COLOR: #000000"><img id=Codehighlighter1_770_1517_Open_Image onclick="this.style.display='none'; Codehighlighter1_770_1517_Open_Text.style.display='none'; Codehighlighter1_770_1517_Closed_Image.style.display='inline'; Codehighlighter1_770_1517_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_770_1517_Closed_Image onclick="this.style.display='none'; Codehighlighter1_770_1517_Closed_Text.style.display='none'; Codehighlighter1_770_1517_Open_Image.style.display='inline'; Codehighlighter1_770_1517_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_770_1517_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_770_1517_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">40</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;test;<br></span><span style="COLOR: #008080">41</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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">test);<br></span><span style="COLOR: #008080">42</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(test</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">43</span><span style="COLOR: #000000"><img id=Codehighlighter1_831_1501_Open_Image onclick="this.style.display='none'; Codehighlighter1_831_1501_Open_Text.style.display='none'; Codehighlighter1_831_1501_Closed_Image.style.display='inline'; Codehighlighter1_831_1501_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_831_1501_Closed_Image onclick="this.style.display='none'; Codehighlighter1_831_1501_Closed_Text.style.display='none'; Codehighlighter1_831_1501_Open_Image.style.display='inline'; Codehighlighter1_831_1501_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_831_1501_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_831_1501_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">44</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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">n,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">m);<br></span><span style="COLOR: #008080">45</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data.clear();<br></span><span style="COLOR: #008080">46</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;refer.clear();<br></span><span style="COLOR: #008080">47</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&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">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">48</span><span style="COLOR: #000000"><img id=Codehighlighter1_939_1142_Open_Image onclick="this.style.display='none'; Codehighlighter1_939_1142_Open_Text.style.display='none'; Codehighlighter1_939_1142_Closed_Image.style.display='inline'; Codehighlighter1_939_1142_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_939_1142_Closed_Image onclick="this.style.display='none'; Codehighlighter1_939_1142_Closed_Text.style.display='none'; Codehighlighter1_939_1142_Open_Image.style.display='inline'; Codehighlighter1_939_1142_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_939_1142_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_939_1142_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">49</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;type[</span><span style="COLOR: #000000">128</span><span style="COLOR: #000000">],name[</span><span style="COLOR: #000000">128</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">50</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;p,q;<br></span><span style="COLOR: #008080">51</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s%s%d%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,type,name,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">p,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">q);<br></span><span style="COLOR: #008080">52</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data[</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">(type)].push_back(node(</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">(name),p,q));<br></span><span style="COLOR: #008080">53</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;refer.push_back(q);<br></span><span style="COLOR: #008080">54</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">55</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort(refer.begin(),refer.end());<br></span><span style="COLOR: #008080">56</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">::iterator&nbsp;end</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">unique(refer.begin(),refer.end());<br></span><span style="COLOR: #008080">57</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(refer.end()</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">end)&nbsp;refer.pop_back();<br></span><span style="COLOR: #008080">58</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;s</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,e</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">refer.size()</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">59</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(s</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">e)<br></span><span style="COLOR: #008080">60</span><span style="COLOR: #000000"><img id=Codehighlighter1_1360_1460_Open_Image onclick="this.style.display='none'; Codehighlighter1_1360_1460_Open_Text.style.display='none'; Codehighlighter1_1360_1460_Closed_Image.style.display='inline'; Codehighlighter1_1360_1460_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1360_1460_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1360_1460_Closed_Text.style.display='none'; Codehighlighter1_1360_1460_Open_Image.style.display='inline'; Codehighlighter1_1360_1460_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1360_1460_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1360_1460_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">61</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;mid</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(s</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">e)</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">62</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(chk(refer[mid]))&nbsp;s</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">mid</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">63</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;e</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">mid</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">64</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">65</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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">,refer[s</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);<br></span><span style="COLOR: #008080">66</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">67</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">68</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">69</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br></span><span style="COLOR: #008080">70</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
<img src ="http://www.cppblog.com/yzhw/aggbug/135301.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2010-12-02 22:42 <a href="http://www.cppblog.com/yzhw/archive/2010/12/02/135301.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku 1209 Calendar 历法问题，超多trick</title><link>http://www.cppblog.com/yzhw/archive/2010/11/26/134752.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Fri, 26 Nov 2010 12:38:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2010/11/26/134752.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/134752.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2010/11/26/134752.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/134752.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/134752.html</trackback:ping><description><![CDATA[<p>简要题意：<br>给出1900-1999
年中任一一年的事件，(d.m.p)，分别表示日、月、重要度（提前p天需要通知）。然后给出n个时间点，要求输出需要提醒的日期。排序规则很诡异（与官
方测试数据不同），引poj的discuss：先是按时间排，时间相同就看是不是今天，是今天就只管输入顺序，不是今天就先考虑星星的问题再来输入顺序。</p>
<p>我的解法：<br>将事件看做区间，开一个366的二维数组或者vector，来记录覆盖每个时间点的事件。然后对每个数组按照上述排序规则进行排序。<br>输出的时候有点诡异，所有的时间输出采取右对齐并占3字节。<br>还有个更诡异的，时期会套圈。。。（感觉和题意描述有点区别），就是说，如果输出12.31号需要提醒的事件，那么需要考虑1月份的，然后排序的时候1月份还要排在后面。。。。</p>
代码：<br>
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080;">&nbsp;&nbsp;1</span>&nbsp;<span style="color: #000000;">Source&nbsp;Code<br></span><span style="color: #008080;">&nbsp;&nbsp;2</span>&nbsp;<span style="color: #000000;">Problem:&nbsp;</span><span style="color: #000000;">1209</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User:&nbsp;yzhw<br></span><span style="color: #008080;">&nbsp;&nbsp;3</span>&nbsp;<span style="color: #000000;">Memory:&nbsp;616K&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Time:&nbsp;0MS<br></span><span style="color: #008080;">&nbsp;&nbsp;4</span>&nbsp;<span style="color: #000000;">Language:&nbsp;G</span><span style="color: #000000;">++</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Result:&nbsp;Accepted<br></span><span style="color: #008080;">&nbsp;&nbsp;5</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;&nbsp;6</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">&nbsp;Source&nbsp;Code<br></span><span style="color: #008080;">&nbsp;&nbsp;7</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;&nbsp;8</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">cstdio</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;&nbsp;9</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;include&nbsp;</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: #008080;">&nbsp;10</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">cstring</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;11</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;12</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">algorithm</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;13</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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: #008080;">&nbsp;14</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;node<br></span><span style="color: #008080;">&nbsp;15</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;16</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;t,r,id,d,m;<br></span><span style="color: #008080;">&nbsp;17</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;name[</span><span style="color: #000000;">255</span><span style="color: #000000;">];<br></span><span style="color: #008080;">&nbsp;18</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">bool</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">operator</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">(</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;node&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">pos)&nbsp;</span><span style="color: #0000ff;">const</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;19</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;20</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(t</span><span style="color: #000000;">!=</span><span style="color: #000000;">pos.t)&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;t</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">pos.t;<br></span><span style="color: #008080;">&nbsp;21</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;">(r</span><span style="color: #000000;">!=</span><span style="color: #000000;">pos.r)&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;r</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">pos.r;<br></span><span style="color: #008080;">&nbsp;22</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;id</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">pos.id;<br></span><span style="color: #008080;">&nbsp;23</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">&nbsp;24</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<br></span><span style="color: #008080;">&nbsp;25</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">node</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;day[</span><span style="color: #000000;">400</span><span style="color: #000000;">];<br></span><span style="color: #008080;">&nbsp;26</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;27</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;main()&nbsp;{<br></span><span style="color: #008080;">&nbsp;28</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">&nbsp;&nbsp;&nbsp;&nbsp;freopen("c.in","r",stdin);<br></span><span style="color: #008080;">&nbsp;29</span>&nbsp;<span style="color: #008000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">&nbsp;&nbsp;&nbsp;&nbsp;freopen("ans.txt","w",stdout);</span><span style="color: #008000;"><br></span><span style="color: #008080;">&nbsp;30</span>&nbsp;<span style="color: #008000;"></span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;year,c</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;31</span>&nbsp;<span style="color: #000000;">&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;">year);<br></span><span style="color: #008080;">&nbsp;32</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;time[</span><span style="color: #000000;">13</span><span style="color: #000000;">];<br></span><span style="color: #008080;">&nbsp;33</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;time[</span><span style="color: #000000;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;34</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;">1</span><span style="color: #000000;">;i</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">12</span><span style="color: #000000;">;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;35</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(i</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">7</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">i</span><span style="color: #000000;">%</span><span style="color: #000000;">2</span><span style="color: #000000;">||</span><span style="color: #000000;">i</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">7</span><span style="color: #000000;">&amp;&amp;!</span><span style="color: #000000;">(i</span><span style="color: #000000;">%</span><span style="color: #000000;">2</span><span style="color: #000000;">))<br></span><span style="color: #008080;">&nbsp;36</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;time[i]</span><span style="color: #000000;">=</span><span style="color: #000000;">31</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;37</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;38</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;time[i]</span><span style="color: #000000;">=</span><span style="color: #000000;">30</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;39</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(year</span><span style="color: #000000;">%</span><span style="color: #000000;">4</span><span style="color: #000000;">==</span><span style="color: #000000;">0</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;40</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;time[</span><span style="color: #000000;">2</span><span style="color: #000000;">]</span><span style="color: #000000;">=</span><span style="color: #000000;">29</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;41</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;42</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;time[</span><span style="color: #000000;">2</span><span style="color: #000000;">]</span><span style="color: #000000;">=</span><span style="color: #000000;">28</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;43</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;">2</span><span style="color: #000000;">;i</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">12</span><span style="color: #000000;">;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;44</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;time[i]</span><span style="color: #000000;">+=</span><span style="color: #000000;">time[i</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">];<br></span><span style="color: #008080;">&nbsp;45</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">bool</span><span style="color: #000000;">&nbsp;flag</span><span style="color: #000000;">=</span><span style="color: #0000ff;">false</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;46</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">(</span><span style="color: #0000ff;">true</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;47</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;48</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;jud[</span><span style="color: #000000;">5</span><span style="color: #000000;">];<br></span><span style="color: #008080;">&nbsp;49</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%s</span><span style="color: #000000;">"</span><span style="color: #000000;">,jud);<br></span><span style="color: #008080;">&nbsp;50</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(jud[</span><span style="color: #000000;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">==</span><span style="color: #000000;">'</span><span style="color: #000000;">#</span><span style="color: #000000;">'</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;51</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;">(jud[</span><span style="color: #000000;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">==</span><span style="color: #000000;">'</span><span style="color: #000000;">A</span><span style="color: #000000;">'</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;52</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;53</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;d,m,l;<br></span><span style="color: #008080;">&nbsp;54</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%d%d%d</span><span style="color: #000000;">"</span><span style="color: #000000;">,</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">d,</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">m,</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">l);<br></span><span style="color: #008080;">&nbsp;55</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;str[</span><span style="color: #000000;">300</span><span style="color: #000000;">];<br></span><span style="color: #008080;">&nbsp;56</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gets(str);<br></span><span style="color: #008080;">&nbsp;57</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">(str[</span><span style="color: #000000;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">==</span><span style="color: #000000;">'</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">'</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;58</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;">strlen(str);i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;59</span>&nbsp;<span style="color: #000000;">&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;str[i]</span><span style="color: #000000;">=</span><span style="color: #000000;">str[i</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">];<br></span><span style="color: #008080;">&nbsp;60</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;">max(</span><span style="color: #000000;">1</span><span style="color: #000000;">,time[m</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">d</span><span style="color: #000000;">-</span><span style="color: #000000;">l);i</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">time[m</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">d;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;61</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;62</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;node&nbsp;tmp;<br></span><span style="color: #008080;">&nbsp;63</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcpy(tmp.name,str);<br></span><span style="color: #008080;">&nbsp;64</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp.id</span><span style="color: #000000;">=</span><span style="color: #000000;">c;<br></span><span style="color: #008080;">&nbsp;65</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp.d</span><span style="color: #000000;">=</span><span style="color: #000000;">d;<br></span><span style="color: #008080;">&nbsp;66</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp.m</span><span style="color: #000000;">=</span><span style="color: #000000;">m;<br></span><span style="color: #008080;">&nbsp;67</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(i</span><span style="color: #000000;">!=</span><span style="color: #000000;">time[m</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">d)<br></span><span style="color: #008080;">&nbsp;68</span>&nbsp;<span style="color: #000000;">&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;tmp.r</span><span style="color: #000000;">=</span><span style="color: #000000;">l</span><span style="color: #000000;">-</span><span style="color: #000000;">(time[m</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">d</span><span style="color: #000000;">-</span><span style="color: #000000;">i</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br></span><span style="color: #008080;">&nbsp;69</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;70</span>&nbsp;<span style="color: #000000;">&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;tmp.r</span><span style="color: #000000;">=</span><span style="color: #000000;">8</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;71</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp.t</span><span style="color: #000000;">=</span><span style="color: #000000;">time[m</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">d;<br></span><span style="color: #008080;">&nbsp;72</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;day[i].push_back(tmp);<br></span><span style="color: #008080;">&nbsp;73</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">&nbsp;74</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;75</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;">time[</span><span style="color: #000000;">12</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">time[m</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">d</span><span style="color: #000000;">-</span><span style="color: #000000;">l;i</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">time[</span><span style="color: #000000;">12</span><span style="color: #000000;">];i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;76</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;77</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;node&nbsp;tmp;<br></span><span style="color: #008080;">&nbsp;78</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcpy(tmp.name,str);<br></span><span style="color: #008080;">&nbsp;79</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp.id</span><span style="color: #000000;">=</span><span style="color: #000000;">c;<br></span><span style="color: #008080;">&nbsp;80</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp.d</span><span style="color: #000000;">=</span><span style="color: #000000;">d;<br></span><span style="color: #008080;">&nbsp;81</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp.m</span><span style="color: #000000;">=</span><span style="color: #000000;">m;<br></span><span style="color: #008080;">&nbsp;82</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp.r</span><span style="color: #000000;">=</span><span style="color: #000000;">l</span><span style="color: #000000;">-</span><span style="color: #000000;">(time[m</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">d</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">+</span><span style="color: #000000;">time[</span><span style="color: #000000;">12</span><span style="color: #000000;">]</span><span style="color: #000000;">-</span><span style="color: #000000;">i</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br></span><span style="color: #008080;">&nbsp;83</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp.t</span><span style="color: #000000;">=</span><span style="color: #000000;">time[m</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">d</span><span style="color: #000000;">+</span><span style="color: #000000;">time[</span><span style="color: #000000;">12</span><span style="color: #000000;">];<br></span><span style="color: #008080;">&nbsp;84</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;day[i].push_back(tmp);<br></span><span style="color: #008080;">&nbsp;85</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">&nbsp;86</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;87</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">&nbsp;88</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;89</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;90</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;">flag)<br></span><span style="color: #008080;">&nbsp;91</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;92</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flag</span><span style="color: #000000;">=</span><span style="color: #0000ff;">true</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;93</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;">time[</span><span style="color: #000000;">12</span><span style="color: #000000;">];i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;94</span>&nbsp;<span style="color: #000000;">&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;sort(day[i].begin(),day[i].end());<br></span><span style="color: #008080;">&nbsp;95</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">&nbsp;96</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;d,m;<br></span><span style="color: #008080;">&nbsp;97</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;">d,</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">m);<br></span><span style="color: #008080;">&nbsp;98</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Today&nbsp;is:%3d%3d\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,d,m);<br></span><span style="color: #008080;">&nbsp;99</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;">day[time[m</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">d].size();i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">100</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">101</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%3d%3d&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">,day[time[m</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">d][i].d,day[time[m</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">d][i].m);<br></span><span style="color: #008080;">102</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(day[time[m</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">d][i].t</span><span style="color: #000000;">==</span><span style="color: #000000;">time[m</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">d)&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">*TODAY*</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br></span><span style="color: #008080;">103</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br></span><span style="color: #008080;">104</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">105</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;j</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;j</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">day[time[m</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">d][i].r;j</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">106</span>&nbsp;<span style="color: #000000;">&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;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">*</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br></span><span style="color: #008080;">107</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;j</span><span style="color: #000000;">=</span><span style="color: #000000;">day[time[m</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">d][i].r</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">;j</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">8</span><span style="color: #000000;">;j</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">108</span>&nbsp;<span style="color: #000000;">&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;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br></span><span style="color: #008080;">109</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">110</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;%s\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,day[time[m</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">d][i].name);<br></span><span style="color: #008080;">111</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">112</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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></span><span style="color: #008080;">113</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">114</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">115</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">116</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">117</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">118</span>&nbsp;<span style="color: #000000;"></span></div>
<br><img src ="http://www.cppblog.com/yzhw/aggbug/134752.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2010-11-26 20:38 <a href="http://www.cppblog.com/yzhw/archive/2010/11/26/134752.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku 2823 Sliding Window 赤裸裸的单调队列，G++还TLE，C++5S不到。。orz</title><link>http://www.cppblog.com/yzhw/archive/2010/11/08/133041.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Mon, 08 Nov 2010 15:54:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2010/11/08/133041.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/133041.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2010/11/08/133041.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/133041.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/133041.html</trackback:ping><description><![CDATA[不解释了，求固定长度的区间最大值和最小值，单调队列即可。。<br>
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080;">&nbsp;1</span>&nbsp;<span style="color: #000000;">#&nbsp;include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">cstdio</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;2</span>&nbsp;<span style="color: #000000;"></span><span style="color: #008000;">//</span><span style="color: #008000;">#&nbsp;include&nbsp;&lt;iostream&gt;</span><span style="color: #008000;"><br></span><span style="color: #008080;">&nbsp;3</span>&nbsp;<span style="color: #008000;"></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: #008080;">&nbsp;4</span>&nbsp;<span style="color: #000000;"></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;">1000005</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;5</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;data[N],q[N],s</span><span style="color: #000000;">=-</span><span style="color: #000000;">1</span><span style="color: #000000;">,e</span><span style="color: #000000;">=-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;6</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;main()<br></span><span style="color: #008080;">&nbsp;7</span>&nbsp;<span style="color: #000000;">{<br></span><span style="color: #008080;">&nbsp;8</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;n,k;<br></span><span style="color: #008080;">&nbsp;9</span>&nbsp;<span style="color: #000000;">&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;">n,</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">k);<br></span><span style="color: #008080;">10</span>&nbsp;<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;">n;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">11</span>&nbsp;<span style="color: #000000;">&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;">,data</span><span style="color: #000000;">+</span><span style="color: #000000;">i);<br></span><span style="color: #008080;">12</span>&nbsp;<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;">n;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">13</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">14</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">(s</span><span style="color: #000000;">!=</span><span style="color: #000000;">e</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">i</span><span style="color: #000000;">-</span><span style="color: #000000;">q[s</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">&gt;=</span><span style="color: #000000;">k)&nbsp;s</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br></span><span style="color: #008080;">15</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">(s</span><span style="color: #000000;">!=</span><span style="color: #000000;">e</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">data[q[e]]</span><span style="color: #000000;">&gt;=</span><span style="color: #000000;">data[i])&nbsp;e</span><span style="color: #000000;">--</span><span style="color: #000000;">;<br></span><span style="color: #008080;">16</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q[</span><span style="color: #000000;">++</span><span style="color: #000000;">e]</span><span style="color: #000000;">=</span><span style="color: #000000;">i;<br></span><span style="color: #008080;">17</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(i</span><span style="color: #000000;">&gt;=</span><span style="color: #000000;">k</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%d%c</span><span style="color: #000000;">"</span><span style="color: #000000;">,data[q[s</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">]],i</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;">'</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">'</span><span style="color: #000000;">:</span><span style="color: #000000;">'</span><span style="color: #000000;">\n</span><span style="color: #000000;">'</span><span style="color: #000000;">);<br></span><span style="color: #008080;">18</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">19</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;s</span><span style="color: #000000;">=</span><span style="color: #000000;">e</span><span style="color: #000000;">=-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br></span><span style="color: #008080;">20</span>&nbsp;<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;">n;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">21</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">22</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">(s</span><span style="color: #000000;">!=</span><span style="color: #000000;">e</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">i</span><span style="color: #000000;">-</span><span style="color: #000000;">q[s</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">&gt;=</span><span style="color: #000000;">k)&nbsp;s</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br></span><span style="color: #008080;">23</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">(s</span><span style="color: #000000;">!=</span><span style="color: #000000;">e</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">data[q[e]]</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">data[i])&nbsp;e</span><span style="color: #000000;">--</span><span style="color: #000000;">;<br></span><span style="color: #008080;">24</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q[</span><span style="color: #000000;">++</span><span style="color: #000000;">e]</span><span style="color: #000000;">=</span><span style="color: #000000;">i;<br></span><span style="color: #008080;">25</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(i</span><span style="color: #000000;">&gt;=</span><span style="color: #000000;">k</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%d%c</span><span style="color: #000000;">"</span><span style="color: #000000;">,data[q[s</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">]],i</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;">'</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">'</span><span style="color: #000000;">:</span><span style="color: #000000;">'</span><span style="color: #000000;">\n</span><span style="color: #000000;">'</span><span style="color: #000000;">);<br></span><span style="color: #008080;">26</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">27</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">&nbsp;system("pause");</span><span style="color: #008000;"><br></span><span style="color: #008080;">28</span>&nbsp;<span style="color: #008000;"></span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">29</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="color: #008080;">30</span>&nbsp;<span style="color: #000000;">}<br></span><span style="color: #008080;">31</span>&nbsp;<span style="color: #000000;"></span></div>
<br><br><img src ="http://www.cppblog.com/yzhw/aggbug/133041.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2010-11-08 23:54 <a href="http://www.cppblog.com/yzhw/archive/2010/11/08/133041.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku 1706 References 简单hash</title><link>http://www.cppblog.com/yzhw/archive/2010/11/07/132827.html</link><dc:creator>yzhw</dc:creator><author>yzhw</author><pubDate>Sat, 06 Nov 2010 18:54:00 GMT</pubDate><guid>http://www.cppblog.com/yzhw/archive/2010/11/07/132827.html</guid><wfw:comment>http://www.cppblog.com/yzhw/comments/132827.html</wfw:comment><comments>http://www.cppblog.com/yzhw/archive/2010/11/07/132827.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yzhw/comments/commentRss/132827.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yzhw/services/trackbacks/132827.html</trackback:ping><description><![CDATA[题意很简单，把文章中的引用信息整理到最后并给它们重新编号。。我想不懂为什么我自己写hash效率那么低。。。还有就是看清题目，空行是仅仅包括空格、TAB、回车的行<br>
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080;">&nbsp;&nbsp;1</span>&nbsp;<span style="color: #000000;">#&nbsp;include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">stdio.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;&nbsp;2</span>&nbsp;<span style="color: #000000;">#&nbsp;include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">stdlib.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;&nbsp;3</span>&nbsp;<span style="color: #000000;">#&nbsp;include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;&nbsp;4</span>&nbsp;<span style="color: #000000;"></span><span style="color: #008000;">//</span><span style="color: #008000;">char&nbsp;tmp[100];</span><span style="color: #008000;"><br></span><span style="color: #008080;">&nbsp;&nbsp;5</span>&nbsp;<span style="color: #008000;"></span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;part<br></span><span style="color: #008080;">&nbsp;&nbsp;6</span>&nbsp;<span style="color: #000000;">{<br></span><span style="color: #008080;">&nbsp;&nbsp;7</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;tmp[</span><span style="color: #000000;">3</span><span style="color: #000000;">][</span><span style="color: #000000;">100</span><span style="color: #000000;">];<br></span><span style="color: #008080;">&nbsp;&nbsp;8</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;c;<br></span><span style="color: #008080;">&nbsp;&nbsp;9</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;id;<br></span><span style="color: #008080;">&nbsp;10</span>&nbsp;<span style="color: #000000;">}refer[</span><span style="color: #000000;">40001</span><span style="color: #000000;">];<br></span><span style="color: #008080;">&nbsp;11</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;c</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">,hashc</span><span style="color: #000000;">=</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;12</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;hash_map[</span><span style="color: #000000;">100001</span><span style="color: #000000;">][</span><span style="color: #000000;">2</span><span style="color: #000000;">];<br></span><span style="color: #008080;">&nbsp;13</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">void</span><span style="color: #000000;">&nbsp;puthash(</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;num,</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;val)<br></span><span style="color: #008080;">&nbsp;14</span>&nbsp;<span style="color: #000000;">{<br></span><span style="color: #008080;">&nbsp;15</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;h</span><span style="color: #000000;">=</span><span style="color: #000000;">num</span><span style="color: #000000;">%</span><span style="color: #000000;">99997</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;16</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">(hash_map[h][</span><span style="color: #000000;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">!=-</span><span style="color: #000000;">1</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">hash_map[h][</span><span style="color: #000000;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">!=</span><span style="color: #000000;">num)<br></span><span style="color: #008080;">&nbsp;17</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h</span><span style="color: #000000;">=</span><span style="color: #000000;">(h</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">)</span><span style="color: #000000;">%</span><span style="color: #000000;">100000</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;18</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(hash_map[h][</span><span style="color: #000000;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">==-</span><span style="color: #000000;">1</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;19</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;20</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hash_map[h][</span><span style="color: #000000;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">=</span><span style="color: #000000;">num;<br></span><span style="color: #008080;">&nbsp;21</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hash_map[h][</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">=</span><span style="color: #000000;">val;<br></span><span style="color: #008080;">&nbsp;22</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;23</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">&nbsp;24</span>&nbsp;<span style="color: #000000;">}<br></span><span style="color: #008080;">&nbsp;25</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;gethash(</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;num)<br></span><span style="color: #008080;">&nbsp;26</span>&nbsp;<span style="color: #000000;">{<br></span><span style="color: #008080;">&nbsp;27</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;h</span><span style="color: #000000;">=</span><span style="color: #000000;">num</span><span style="color: #000000;">%</span><span style="color: #000000;">99997</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;28</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">(hash_map[h][</span><span style="color: #000000;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">!=-</span><span style="color: #000000;">1</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">hash_map[h][</span><span style="color: #000000;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">!=</span><span style="color: #000000;">num)<br></span><span style="color: #008080;">&nbsp;29</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h</span><span style="color: #000000;">=</span><span style="color: #000000;">(h</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">)</span><span style="color: #000000;">%</span><span style="color: #000000;">100000</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;30</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(hash_map[h][</span><span style="color: #000000;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">==-</span><span style="color: #000000;">1</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;31</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;32</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;33</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;hash_map[h][</span><span style="color: #000000;">1</span><span style="color: #000000;">];<br></span><span style="color: #008080;">&nbsp;34</span>&nbsp;<span style="color: #000000;">}<br></span><span style="color: #008080;">&nbsp;35</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;cmp(</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">void</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">a,</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">void</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">b)<br></span><span style="color: #008080;">&nbsp;36</span>&nbsp;<span style="color: #000000;">{<br></span><span style="color: #008080;">&nbsp;37</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;part&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">aa</span><span style="color: #000000;">=</span><span style="color: #000000;">(</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;part&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">)a;<br></span><span style="color: #008080;">&nbsp;38</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;part&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">bb</span><span style="color: #000000;">=</span><span style="color: #000000;">(</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;part&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">)b;<br></span><span style="color: #008080;">&nbsp;39</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;aa</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">id</span><span style="color: #000000;">-</span><span style="color: #000000;">bb</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">id;<br></span><span style="color: #008080;">&nbsp;40</span>&nbsp;<span style="color: #000000;">}<br></span><span style="color: #008080;">&nbsp;41</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;emptyline(</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">str)<br></span><span style="color: #008080;">&nbsp;42</span>&nbsp;<span style="color: #000000;">{<br></span><span style="color: #008080;">&nbsp;43</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;i;<br></span><span style="color: #008080;">&nbsp;44</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(strlen(str)</span><span style="color: #000000;">==</span><span style="color: #000000;">0</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;45</span>&nbsp;<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;">0</span><span style="color: #000000;">;i</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">strlen(str);i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;46</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(str[i]</span><span style="color: #000000;">!=</span><span style="color: #000000;">'</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">'</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">str[i]</span><span style="color: #000000;">!=</span><span style="color: #000000;">'</span><span style="color: #000000;">\t</span><span style="color: #000000;">'</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;47</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;48</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">1</span><span style="color: #000000;">;&nbsp;&nbsp;&nbsp;<br></span><span style="color: #008080;">&nbsp;49</span>&nbsp;<span style="color: #000000;">}<br></span><span style="color: #008080;">&nbsp;50</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;main()<br></span><span style="color: #008080;">&nbsp;51</span>&nbsp;<span style="color: #000000;">{<br></span><span style="color: #008080;">&nbsp;52</span>&nbsp;<span style="color: #000000;"></span><span style="color: #008000;">//</span><span style="color: #008000;">&nbsp;&nbsp;&nbsp;&nbsp;freopen("input.txt","r",stdin);<br></span><span style="color: #008080;">&nbsp;53</span>&nbsp;<span style="color: #008000;"></span><span style="color: #008000;">//</span><span style="color: #008000;">&nbsp;&nbsp;&nbsp;&nbsp;freopen("ans.txt","w",stdout);</span><span style="color: #008000;"><br></span><span style="color: #008080;">&nbsp;54</span>&nbsp;<span style="color: #008000;"></span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;i,j;<br></span><span style="color: #008080;">&nbsp;55</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;str[</span><span style="color: #000000;">100</span><span style="color: #000000;">];<br></span><span style="color: #008080;">&nbsp;56</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;jud</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;57</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;memset(hash_map,</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">,</span><span style="color: #0000ff;">sizeof</span><span style="color: #000000;">(hash_map));<br></span><span style="color: #008080;">&nbsp;58</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="color: #008080;">&nbsp;59</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">(gets(str))<br></span><span style="color: #008080;">&nbsp;60</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;61</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">if(!strcmp(str,"---"))&nbsp;break;</span><span style="color: #008000;"><br></span><span style="color: #008080;">&nbsp;62</span>&nbsp;<span style="color: #008000;"></span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(str[</span><span style="color: #000000;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">==</span><span style="color: #000000;">'</span><span style="color: #000000;">[</span><span style="color: #000000;">'</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;63</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;64</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&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;">0</span><span style="color: #000000;">;str[i]</span><span style="color: #000000;">!=</span><span style="color: #000000;">'</span><span style="color: #000000;">]</span><span style="color: #000000;">'</span><span style="color: #000000;">;i</span><span style="color: #000000;">++</span><span style="color: #000000;">);<br></span><span style="color: #008080;">&nbsp;65</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str[i]</span><span style="color: #000000;">=</span><span style="color: #000000;">'</span><span style="color: #000000;">\0</span><span style="color: #000000;">'</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;66</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;refer[c].id</span><span style="color: #000000;">=</span><span style="color: #000000;">atoi(str</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br></span><span style="color: #008080;">&nbsp;67</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;refer[c].c</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;68</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcpy(refer[c].tmp[refer[c].c</span><span style="color: #000000;">++</span><span style="color: #000000;">],str</span><span style="color: #000000;">+</span><span style="color: #000000;">i</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br></span><span style="color: #008080;">&nbsp;69</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">(gets(str))<br></span><span style="color: #008080;">&nbsp;70</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;71</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(emptyline(str))&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;72</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="color: #008080;">&nbsp;73</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;74</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;75</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcpy(refer[c].tmp[refer[c].c</span><span style="color: #000000;">++</span><span style="color: #000000;">],str);<br></span><span style="color: #008080;">&nbsp;76</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">&nbsp;77</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">&nbsp;78</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;79</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">&nbsp;80</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&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;">(emptyline(str))&nbsp;</span><span style="color: #0000ff;">continue</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;81</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;82</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;83</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(jud</span><span style="color: #000000;">==</span><span style="color: #000000;">0</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;84</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jud</span><span style="color: #000000;">=</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;85</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;86</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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></span><span style="color: #008080;">&nbsp;87</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">do</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;88</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;89</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(emptyline(str))&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br></span><span style="color: #008080;">&nbsp;90</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;91</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;">0</span><span style="color: #000000;">;i</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">strlen(str);i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;92</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;93</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(str[i]</span><span style="color: #000000;">!=</span><span style="color: #000000;">'</span><span style="color: #000000;">[</span><span style="color: #000000;">'</span><span style="color: #000000;">)<br></span><span style="color: #008080;">&nbsp;94</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%c</span><span style="color: #000000;">"</span><span style="color: #000000;">,str[i]);<br></span><span style="color: #008080;">&nbsp;95</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;96</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">&nbsp;97</span>&nbsp;<span style="color: #000000;">&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><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;num,h;<br></span><span style="color: #008080;">&nbsp;98</span>&nbsp;<span style="color: #000000;">&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><span style="color: #0000ff;">for</span><span style="color: #000000;">(j</span><span style="color: #000000;">=</span><span style="color: #000000;">i;str[j]</span><span style="color: #000000;">!=</span><span style="color: #000000;">'</span><span style="color: #000000;">]</span><span style="color: #000000;">'</span><span style="color: #000000;">;j</span><span style="color: #000000;">++</span><span style="color: #000000;">);<br></span><span style="color: #008080;">&nbsp;99</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str[j]</span><span style="color: #000000;">=</span><span style="color: #000000;">'</span><span style="color: #000000;">\0</span><span style="color: #000000;">'</span><span style="color: #000000;">;<br></span><span style="color: #008080;">100</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num</span><span style="color: #000000;">=</span><span style="color: #000000;">atoi(str</span><span style="color: #000000;">+</span><span style="color: #000000;">i</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br></span><span style="color: #008080;">101</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str[j]</span><span style="color: #000000;">=</span><span style="color: #000000;">'</span><span style="color: #000000;">]</span><span style="color: #000000;">'</span><span style="color: #000000;">;<br></span><span style="color: #008080;">102</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h</span><span style="color: #000000;">=</span><span style="color: #000000;">gethash(num);<br></span><span style="color: #008080;">103</span>&nbsp;<span style="color: #000000;">&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><span style="color: #0000ff;">if</span><span style="color: #000000;">(h</span><span style="color: #000000;">==-</span><span style="color: #000000;">1</span><span style="color: #000000;">)<br></span><span style="color: #008080;">104</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">105</span>&nbsp;<span style="color: #000000;">&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;puthash(num,hashc);<br></span><span style="color: #008080;">106</span>&nbsp;<span style="color: #000000;">&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;h</span><span style="color: #000000;">=</span><span style="color: #000000;">hashc</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br></span><span style="color: #008080;">107</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">108</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;">,h);<br></span><span style="color: #008080;">109</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="color: #000000;">=</span><span style="color: #000000;">j;<br></span><span style="color: #008080;">110</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">111</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">112</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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></span><span style="color: #008080;">113</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="color: #008080;">114</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="color: #0000ff;">while</span><span style="color: #000000;">(gets(str));<br></span><span style="color: #008080;">115</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">116</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">117</span>&nbsp;<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;">0</span><span style="color: #000000;">;i</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">c;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">118</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">119</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;res</span><span style="color: #000000;">=</span><span style="color: #000000;">gethash(refer[i].id);<br></span><span style="color: #008080;">120</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(res</span><span style="color: #000000;">==-</span><span style="color: #000000;">1</span><span style="color: #000000;">)<br></span><span style="color: #008080;">121</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">122</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puthash(refer[i].id,hashc);<br></span><span style="color: #008080;">123</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res</span><span style="color: #000000;">=</span><span style="color: #000000;">hashc</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br></span><span style="color: #008080;">124</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">125</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;refer[i].id</span><span style="color: #000000;">=</span><span style="color: #000000;">res;<br></span><span style="color: #008080;">126</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">127</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;qsort(refer,c,</span><span style="color: #0000ff;">sizeof</span><span style="color: #000000;">(</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;part),cmp);<br></span><span style="color: #008080;">128</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">129</span>&nbsp;<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;">0</span><span style="color: #000000;">;i</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">c;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">130</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="color: #008080;">131</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&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></span><span style="color: #008080;">132</span>&nbsp;<span style="color: #000000;">&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;">,refer[i].id);<br></span><span style="color: #008080;">133</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(j</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;j</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">refer[i].c;j</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br></span><span style="color: #008080;">134</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%s\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,refer[i].tmp[j]);<br></span><span style="color: #008080;">135</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="color: #008080;">136</span>&nbsp;<span style="color: #000000;">printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">\n</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br></span><span style="color: #008080;">137</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">138</span>&nbsp;<span style="color: #000000;">}<br></span><span style="color: #008080;">139</span>&nbsp;<span style="color: #000000;"></span></div>
<br><br><br><img src ="http://www.cppblog.com/yzhw/aggbug/132827.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yzhw/" target="_blank">yzhw</a> 2010-11-07 02:54 <a href="http://www.cppblog.com/yzhw/archive/2010/11/07/132827.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>