﻿<?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++博客-Darren-随笔分类-数据结构</title><link>http://www.cppblog.com/Darren/category/12421.html</link><description>C++ 及算法</description><language>zh-cn</language><lastBuildDate>Fri, 27 Nov 2009 14:00:58 GMT</lastBuildDate><pubDate>Fri, 27 Nov 2009 14:00:58 GMT</pubDate><ttl>60</ttl><item><title>HDU   1255</title><link>http://www.cppblog.com/Darren/archive/2009/08/06/92384.html</link><dc:creator>Darren</dc:creator><author>Darren</author><pubDate>Thu, 06 Aug 2009 01:59:00 GMT</pubDate><guid>http://www.cppblog.com/Darren/archive/2009/08/06/92384.html</guid><wfw:comment>http://www.cppblog.com/Darren/comments/92384.html</wfw:comment><comments>http://www.cppblog.com/Darren/archive/2009/08/06/92384.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Darren/comments/commentRss/92384.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Darren/services/trackbacks/92384.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">algorithm</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000"> N 2110</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img id="Codehighlighter1_91_200_Open_Image" onclick="this.style.display='none'; Codehighlighter1_91_200_Open_Text.style.display='none'; Codehighlighter1_91_200_Closed_Image.style.display='inline'; Codehighlighter1_91_200_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_91_200_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_91_200_Closed_Text.style.display='none'; Codehighlighter1_91_200_Open_Image.style.display='inline'; Codehighlighter1_91_200_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> Tree</span>
				<span id="Codehighlighter1_91_200_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_91_200_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">double</span>
						<span style="COLOR: #000000"> length, len;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">    cnt;<br /><img id="Codehighlighter1_134_155_Open_Image" onclick="this.style.display='none'; Codehighlighter1_134_155_Open_Text.style.display='none'; Codehighlighter1_134_155_Closed_Image.style.display='inline'; Codehighlighter1_134_155_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_134_155_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_134_155_Closed_Text.style.display='none'; Codehighlighter1_134_155_Open_Image.style.display='inline'; Codehighlighter1_134_155_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    Tree()</span>
						<span id="Codehighlighter1_134_155_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_134_155_Open_Text">
								<span style="COLOR: #000000">{ length</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">; cnt</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">; }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_169_198_Open_Image" onclick="this.style.display='none'; Codehighlighter1_169_198_Open_Text.style.display='none'; Codehighlighter1_169_198_Closed_Image.style.display='inline'; Codehighlighter1_169_198_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_169_198_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_169_198_Closed_Text.style.display='none'; Codehighlighter1_169_198_Open_Image.style.display='inline'; Codehighlighter1_169_198_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> init()</span>
						<span id="Codehighlighter1_169_198_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_169_198_Open_Text">
								<span style="COLOR: #000000">{ length</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">; cnt</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">; len</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">; }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">tb[</span>
				<span style="COLOR: #000000">10100</span>
				<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">double</span>
				<span style="COLOR: #000000"> x1[N], y1[N], x2[N], y2[N], xx[N], idx[N];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> pos, n;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_287_320_Open_Image" onclick="this.style.display='none'; Codehighlighter1_287_320_Open_Text.style.display='none'; Codehighlighter1_287_320_Closed_Image.style.display='inline'; Codehighlighter1_287_320_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_287_320_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_287_320_Closed_Text.style.display='none'; Codehighlighter1_287_320_Open_Image.style.display='inline'; Codehighlighter1_287_320_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> Line</span>
				<span id="Codehighlighter1_287_320_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_287_320_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">double</span>
						<span style="COLOR: #000000"> y, x1, x2;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">bool</span>
						<span style="COLOR: #000000"> type;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">line[N];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_377_397_Open_Image" onclick="this.style.display='none'; Codehighlighter1_377_397_Open_Text.style.display='none'; Codehighlighter1_377_397_Closed_Image.style.display='inline'; Codehighlighter1_377_397_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_377_397_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_377_397_Closed_Text.style.display='none'; Codehighlighter1_377_397_Open_Image.style.display='inline'; Codehighlighter1_377_397_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span style="COLOR: #0000ff">bool</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">operator</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">( Line </span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000"> a, Line </span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000"> b )</span>
				<span id="Codehighlighter1_377_397_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_377_397_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> a.y</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> b.y; }</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    <br /><img id="Codehighlighter1_435_615_Open_Image" onclick="this.style.display='none'; Codehighlighter1_435_615_Open_Text.style.display='none'; Codehighlighter1_435_615_Closed_Image.style.display='inline'; Codehighlighter1_435_615_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_435_615_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_435_615_Closed_Text.style.display='none'; Codehighlighter1_435_615_Open_Image.style.display='inline'; Codehighlighter1_435_615_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />inline </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> bsearch( </span>
				<span style="COLOR: #0000ff">double</span>
				<span style="COLOR: #000000"> value )</span>
				<span id="Codehighlighter1_435_615_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_435_615_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> low</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">, high</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> pos</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_484_613_Open_Image" onclick="this.style.display='none'; Codehighlighter1_484_613_Open_Text.style.display='none'; Codehighlighter1_484_613_Closed_Image.style.display='inline'; Codehighlighter1_484_613_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_484_613_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_484_613_Closed_Text.style.display='none'; Codehighlighter1_484_613_Open_Image.style.display='inline'; Codehighlighter1_484_613_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000">( low</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000"> high )</span>
						<span id="Codehighlighter1_484_613_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_484_613_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> mid</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> (low</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> high)</span>
								<span style="COLOR: #000000">&gt;&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">( idx[mid]</span>
								<span style="COLOR: #000000">&gt;</span>
								<span style="COLOR: #000000"> value ) high</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> mid</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">( idx[mid]</span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000"> value ) low</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> mid</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> mid; }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img id="Codehighlighter1_660_811_Open_Image" onclick="this.style.display='none'; Codehighlighter1_660_811_Open_Text.style.display='none'; Codehighlighter1_660_811_Closed_Image.style.display='inline'; Codehighlighter1_660_811_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_660_811_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_660_811_Closed_Text.style.display='none'; Codehighlighter1_660_811_Open_Image.style.display='inline'; Codehighlighter1_660_811_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />inline </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> update( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> rt, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> l, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> r )</span>
				<span id="Codehighlighter1_660_811_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_660_811_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">( tb[rt].cnt ) tb[rt].length</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> idx[r]</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> idx[l];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">( l</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"> r ) tb[rt].length</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000"> tb[rt].length</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> tb[rt</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">].length</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> tb[(rt</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">].length;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img id="Codehighlighter1_857_1039_Open_Image" onclick="this.style.display='none'; Codehighlighter1_857_1039_Open_Text.style.display='none'; Codehighlighter1_857_1039_Closed_Image.style.display='inline'; Codehighlighter1_857_1039_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_857_1039_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_857_1039_Closed_Text.style.display='none'; Codehighlighter1_857_1039_Open_Image.style.display='inline'; Codehighlighter1_857_1039_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />inline </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> update2( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> rt, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> l, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> r )</span>
				<span id="Codehighlighter1_857_1039_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_857_1039_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">( tb[rt].cnt</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000"> ) tb[rt].len</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> idx[r]</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> idx[l];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">( tb[rt].cnt</span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000"> ) tb[rt].len</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> tb[rt</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">].length</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> tb[(rt</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">].length;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000"> tb[rt].len</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> tb[rt</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">].len</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> tb[(rt</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">].len; }</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img id="Codehighlighter1_1096_1357_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1096_1357_Open_Text.style.display='none'; Codehighlighter1_1096_1357_Closed_Image.style.display='inline'; Codehighlighter1_1096_1357_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_1096_1357_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1096_1357_Closed_Text.style.display='none'; Codehighlighter1_1096_1357_Open_Image.style.display='inline'; Codehighlighter1_1096_1357_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> deal( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> rt, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> l, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> r, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> b, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> t )</span>
				<span id="Codehighlighter1_1096_1357_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1096_1357_Open_Text">
						<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_1119_1189_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1119_1189_Open_Text.style.display='none'; Codehighlighter1_1119_1189_Closed_Image.style.display='inline'; Codehighlighter1_1119_1189_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1119_1189_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1119_1189_Closed_Text.style.display='none'; Codehighlighter1_1119_1189_Open_Image.style.display='inline'; Codehighlighter1_1119_1189_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">( a</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000"> l </span>
						<span style="COLOR: #000000">&amp;&amp;</span>
						<span style="COLOR: #000000"> b</span>
						<span style="COLOR: #000000">&gt;=</span>
						<span style="COLOR: #000000"> r )</span>
						<span id="Codehighlighter1_1119_1189_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1119_1189_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        tb[rt].cnt</span>
								<span style="COLOR: #000000">+=</span>
								<span style="COLOR: #000000"> t; update( rt, l, r ); update2( rt, l, r );  </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000">; }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> mid</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> (l</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> r)</span>
						<span style="COLOR: #000000">&gt;&gt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">( a</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> mid ) deal( rt</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">, l, mid, a, b, t);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">( b</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> mid ) deal( (rt</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">, mid, r, a, b, t );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    update( rt, l, r ); update2( rt, l, r );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img id="Codehighlighter1_1370_2269_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1370_2269_Open_Text.style.display='none'; Codehighlighter1_1370_2269_Closed_Image.style.display='inline'; Codehighlighter1_1370_2269_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_1370_2269_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1370_2269_Closed_Text.style.display='none'; Codehighlighter1_1370_2269_Open_Image.style.display='inline'; Codehighlighter1_1370_2269_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()</span>
				<span id="Codehighlighter1_1370_2269_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1370_2269_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> test</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    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 /><img id="Codehighlighter1_1423_2254_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1423_2254_Open_Text.style.display='none'; Codehighlighter1_1423_2254_Closed_Image.style.display='inline'; Codehighlighter1_1423_2254_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1423_2254_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1423_2254_Closed_Text.style.display='none'; Codehighlighter1_1423_2254_Open_Image.style.display='inline'; Codehighlighter1_1423_2254_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000">( test</span>
						<span style="COLOR: #000000">--</span>
						<span style="COLOR: #000000"> )</span>
						<span id="Codehighlighter1_1423_2254_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1423_2254_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        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 /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000">( </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> i</span>
								<span style="COLOR: #000000">=</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"> </span>
								<span style="COLOR: #000000">10000</span>
								<span style="COLOR: #000000">; </span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">i ) tb[i].init();<br /><img id="Codehighlighter1_1520_1808_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1520_1808_Open_Text.style.display='none'; Codehighlighter1_1520_1808_Closed_Image.style.display='inline'; Codehighlighter1_1520_1808_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1520_1808_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1520_1808_Closed_Text.style.display='none'; Codehighlighter1_1520_1808_Open_Image.style.display='inline'; Codehighlighter1_1520_1808_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000">( </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> i</span>
								<span style="COLOR: #000000">=</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">i ) </span>
								<span id="Codehighlighter1_1520_1808_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_1520_1808_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            scanf(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">%lf%lf%lf%lf</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">, x1</span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> i, y1</span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> i, x2</span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> i, y2</span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> i );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            line[</span>
										<span style="COLOR: #000000">2</span>
										<span style="COLOR: #000000">*</span>
										<span style="COLOR: #000000">i].y</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> y1[i];   line[</span>
										<span style="COLOR: #000000">2</span>
										<span style="COLOR: #000000">*</span>
										<span style="COLOR: #000000">i].x1</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> x1[i]; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            line[</span>
										<span style="COLOR: #000000">2</span>
										<span style="COLOR: #000000">*</span>
										<span style="COLOR: #000000">i].x2</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> x2[i];  line[</span>
										<span style="COLOR: #000000">2</span>
										<span style="COLOR: #000000">*</span>
										<span style="COLOR: #000000">i].type</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            xx[</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"> x1[i]; xx[</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"> </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">]</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> x2[i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            line[</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">].y</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> y2[i];  line[</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">].x1</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> x1[i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            line[</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">].x2</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> x2[i]; line[</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">].type</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        sort( xx, xx</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"> n );    sort( line, line</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"> n );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        pos</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">; idx[</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">]</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> xx[</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000">( </span>
								<span style="COLOR: #0000ff">int</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">; i</span>
								<span style="COLOR: #000000">&lt;</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">i )<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">( xx[i]</span>
								<span style="COLOR: #000000">!=</span>
								<span style="COLOR: #000000"> xx[i</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">] ) idx[</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">pos]</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> xx[i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">double</span>
								<span style="COLOR: #000000"> ans</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_2017_2223_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2017_2223_Open_Text.style.display='none'; Codehighlighter1_2017_2223_Closed_Image.style.display='inline'; Codehighlighter1_2017_2223_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_2017_2223_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2017_2223_Closed_Text.style.display='none'; Codehighlighter1_2017_2223_Open_Image.style.display='inline'; Codehighlighter1_2017_2223_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000">( </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> i</span>
								<span style="COLOR: #000000">=</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"> </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"> </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">; </span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">i )</span>
								<span id="Codehighlighter1_2017_2223_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_2017_2223_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> u</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> bsearch( line[i].x1 ), v</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> bsearch( line[i].x2 );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000">( line[i].type</span>
										<span style="COLOR: #000000">==</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000"> ) deal( </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">, </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">, pos, u, v, </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000"> );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">else</span>
										<span style="COLOR: #000000"> deal( </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">, </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">, pos, u, v, </span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000"> );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            ans</span>
										<span style="COLOR: #000000">+=</span>
										<span style="COLOR: #000000"> tb[</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">].len</span>
										<span style="COLOR: #000000">*</span>
										<span style="COLOR: #000000"> ( line[i</span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">].y</span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000"> line[i].y );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        printf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">%.2lf\n</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">, ans );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
<img src ="http://www.cppblog.com/Darren/aggbug/92384.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Darren/" target="_blank">Darren</a> 2009-08-06 09:59 <a href="http://www.cppblog.com/Darren/archive/2009/08/06/92384.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PKU　　1151</title><link>http://www.cppblog.com/Darren/archive/2009/08/06/92365.html</link><dc:creator>Darren</dc:creator><author>Darren</author><pubDate>Wed, 05 Aug 2009 16:49:00 GMT</pubDate><guid>http://www.cppblog.com/Darren/archive/2009/08/06/92365.html</guid><wfw:comment>http://www.cppblog.com/Darren/comments/92365.html</wfw:comment><comments>http://www.cppblog.com/Darren/archive/2009/08/06/92365.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Darren/comments/commentRss/92365.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Darren/services/trackbacks/92365.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: #include 				&lt;				iostream				&gt;																#include 				&lt;				algorithm				&gt;																																				using				 				namespace				 std;	...&nbsp;&nbsp;<a href='http://www.cppblog.com/Darren/archive/2009/08/06/92365.html'>阅读全文</a><img src ="http://www.cppblog.com/Darren/aggbug/92365.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Darren/" target="_blank">Darren</a> 2009-08-06 00:49 <a href="http://www.cppblog.com/Darren/archive/2009/08/06/92365.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ZJU  3228  Searching the String ( AC 自动机 )</title><link>http://www.cppblog.com/Darren/archive/2009/08/02/91977.html</link><dc:creator>Darren</dc:creator><author>Darren</author><pubDate>Sun, 02 Aug 2009 14:05:00 GMT</pubDate><guid>http://www.cppblog.com/Darren/archive/2009/08/02/91977.html</guid><wfw:comment>http://www.cppblog.com/Darren/comments/91977.html</wfw:comment><comments>http://www.cppblog.com/Darren/archive/2009/08/02/91977.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/Darren/comments/commentRss/91977.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Darren/services/trackbacks/91977.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: #include 				&lt;				iostream				&gt;										#include 				&lt;				queue				&gt;																								using				 				namespace				 std;				#define				 N 100010	...&nbsp;&nbsp;<a href='http://www.cppblog.com/Darren/archive/2009/08/02/91977.html'>阅读全文</a><img src ="http://www.cppblog.com/Darren/aggbug/91977.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Darren/" target="_blank">Darren</a> 2009-08-02 22:05 <a href="http://www.cppblog.com/Darren/archive/2009/08/02/91977.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Pku  1986  Distance Queries</title><link>http://www.cppblog.com/Darren/archive/2009/07/20/90590.html</link><dc:creator>Darren</dc:creator><author>Darren</author><pubDate>Mon, 20 Jul 2009 02:56:00 GMT</pubDate><guid>http://www.cppblog.com/Darren/archive/2009/07/20/90590.html</guid><wfw:comment>http://www.cppblog.com/Darren/comments/90590.html</wfw:comment><comments>http://www.cppblog.com/Darren/archive/2009/07/20/90590.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Darren/comments/commentRss/90590.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Darren/services/trackbacks/90590.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">vector</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<br />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><br /></span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000"> N 40010</span>
				<span style="COLOR: #000000">
						<br />typedef 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"> PAIR;<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> m, n;<br />vector</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">PAIR</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> query[N], map[N];<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> uset[N]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> {</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">}, acs[N], flag[N]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> {</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">}, dis[N]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> {</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">}, ans[N], visite[N]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">{</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">};<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> find( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> x ){<br />    </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000">( x</span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000"> uset[x] ) x</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> uset[x];<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> x; }<br /><br /></span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> join( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> x, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> y ){  uset[ find(x) ]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> uset[ find(y) ]; }<br /><br /></span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> dfs( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> u, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> d ){<br />    uset[u]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> u; acs[u]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> u; dis[u]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> d; visite[u]</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: #0000ff">for</span>
				<span style="COLOR: #000000">( size_t i</span>
				<span style="COLOR: #000000">=</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"> map[u].size(); </span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">i ){<br />        </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> v</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> map[u][i].first, w</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> map[u][i].second;<br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #000000">!</span>
				<span style="COLOR: #000000">visite[v] ){<br />            dfs( v, d</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> w );<br />            join( u, v ); acs[ find(u) ]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> u;  }<br />    }<br />    <br />    flag[u]</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: #0000ff">for</span>
				<span style="COLOR: #000000">( size_t i</span>
				<span style="COLOR: #000000">=</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"> query[u].size(); </span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">i ){<br />        </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> v</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> query[u][i].first, w</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> query[u][i].second;<br />        <br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( flag[v] ) ans[w]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> dis[u]</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> dis[v]</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"> dis[ acs[ find(v) ] ];<br />    }    <br />}<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main(){<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> u, v, d;<br />    </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> s[</span>
				<span style="COLOR: #000000">10</span>
				<span style="COLOR: #000000">];<br />    <br />    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: #0000ff">while</span>
				<span style="COLOR: #000000">( m</span>
				<span style="COLOR: #000000">--</span>
				<span style="COLOR: #000000"> ){<br />        scanf(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">%d%d%d%s</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">u,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">v,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">d,s );<br />        map[u].push_back( PAIR(v,d) );<br />        map[v].push_back( PAIR(u,d) );<br />    }<br />    <br />    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">m );<br />    </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #0000ff">int</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">; i</span>
				<span style="COLOR: #000000">&lt;=</span>
				<span style="COLOR: #000000"> m; </span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">i ){<br />        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">u,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">v );<br />        query[u].push_back( PAIR(v,i) );<br />        query[v].push_back( PAIR(u,i) );<br />    }<br />    memset( flag, </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #0000ff">sizeof</span>
				<span style="COLOR: #000000">(flag) );<br />    memset( visite, </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #0000ff">sizeof</span>
				<span style="COLOR: #000000">(visite) );<br />    <br />    dfs( </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> ); <br />    </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #0000ff">int</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">; i</span>
				<span style="COLOR: #000000">&lt;=</span>
				<span style="COLOR: #000000"> m; </span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">i ) printf(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">%d\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, ans[i] );<br />    <br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />}<br /></span>
		</div>
<img src ="http://www.cppblog.com/Darren/aggbug/90590.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Darren/" target="_blank">Darren</a> 2009-07-20 10:56 <a href="http://www.cppblog.com/Darren/archive/2009/07/20/90590.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Pku  3277  City Horizon</title><link>http://www.cppblog.com/Darren/archive/2009/07/15/90128.html</link><dc:creator>Darren</dc:creator><author>Darren</author><pubDate>Wed, 15 Jul 2009 04:39:00 GMT</pubDate><guid>http://www.cppblog.com/Darren/archive/2009/07/15/90128.html</guid><wfw:comment>http://www.cppblog.com/Darren/comments/90128.html</wfw:comment><comments>http://www.cppblog.com/Darren/archive/2009/07/15/90128.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Darren/comments/commentRss/90128.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Darren/services/trackbacks/90128.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">algorithm</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">cstdio</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">cstdlib</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">cstring</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<br />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><br /></span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000"> N 40001</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000"> max(a,b) ( (a)&gt;(b)?(a):(b) )</span>
				<span style="COLOR: #000000">
						<br />
						<br />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n,d[N</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">], idx[N</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">], pos, f[N</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">];<br /><br /></span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> Node{<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> x, y, ht;<br />    Node( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a</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: #0000ff">int</span>
				<span style="COLOR: #000000"> b</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: #0000ff">int</span>
				<span style="COLOR: #000000"> c</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> ):x(a), y(b), ht(c) {}<br />};<br /><br /></span>
				<span style="COLOR: #0000ff">bool</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">operator</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">( Node </span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000"> a, Node </span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">b ){<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> a.ht</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> b.ht; }<br />Node xyh[N];<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> bsearch( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> v ){<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> left</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">, right</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> n</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">2</span>
				<span style="COLOR: #000000">;<br />    </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000">( left</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> right ){<br />        </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> m</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> (left</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000">right)</span>
				<span style="COLOR: #000000">&gt;&gt;</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">;<br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( d[m]</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> v ) right</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> m;<br />        </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( d[m]</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> v ) left</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> m;<br />        </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> idx[m];<br />    }<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> idx[left]; }<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> tb[N</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">8</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 /><br /></span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> insert( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> l, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> r, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> b, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> rt, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> h ){<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( l</span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> a </span>
				<span style="COLOR: #000000">&amp;&amp;</span>
				<span style="COLOR: #000000"> r</span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> b ){<br />        tb[rt]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> max( tb[rt], h ); </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000">; }<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( tb[rt]</span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> ){<br />        tb[rt</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"> tb[rt];<br />        tb[(rt</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"> tb[rt];<br />        tb[rt]</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: #0000ff">int</span>
				<span style="COLOR: #000000"> m</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> (l</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> r)</span>
				<span style="COLOR: #000000">&gt;&gt;</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">;<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( b</span>
				<span style="COLOR: #000000">&lt;=</span>
				<span style="COLOR: #000000"> m ) insert( l, m, a, b, rt</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, h );<br />    </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( a</span>
				<span style="COLOR: #000000">&gt;=</span>
				<span style="COLOR: #000000"> m ) insert( m, r, a, b, (rt</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">, h );<br />    </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">{<br />        insert( l, m, a, m, rt</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, h );<br />        insert( m, r, m, b, (rt</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">, h ); }<br />}<br /><br />typedef __int64 INT;<br /><br />INT ans;<br /></span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> sum( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> l, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> r, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> rt ){<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( tb[rt]</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> ){<br />        ans</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> ans</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> (INT)( f[r]</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000"> f[l] )</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> (INT)tb[rt];<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000">; }<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( r</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> l</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: #0000ff">int</span>
				<span style="COLOR: #000000"> m</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> (l</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> r)</span>
				<span style="COLOR: #000000">&gt;&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">;<br />        sum( l, m, rt</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> );<br />        sum( m, r, (rt</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"> );<br />    }        <br />}<br /><br />inline </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> read(){<br />    </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> ch;<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> d;<br />    </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000">( (ch</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> getchar()), ch</span>
				<span style="COLOR: #000000">&lt;</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"> ch</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">9</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> );<br />    d</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> ch</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">'</span>
				<span style="COLOR: #000000">;<br />    </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000">( (ch</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> getchar()), ch</span>
				<span style="COLOR: #000000">&gt;=</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">&amp;&amp;</span>
				<span style="COLOR: #000000"> ch</span>
				<span style="COLOR: #000000">&lt;=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">9</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> ) d</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">10</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> ch</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">'</span>
				<span style="COLOR: #000000">;<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> d; }<br />    <br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main(){<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a, b, h;<br />    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: #0000ff">for</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> i</span>
				<span style="COLOR: #000000">=</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">i ){<br />        a</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> read(), b</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> read(), h</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> read();<br />        xyh[i]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> Node( a, b, h );<br />        d[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"> a, d[(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"> b; }<br />    sort( d, d</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> n</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">2</span>
				<span style="COLOR: #000000"> );<br />    pos</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">; idx[</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">1</span>
				<span style="COLOR: #000000">; f[</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">0</span>
				<span style="COLOR: #000000">];<br />    </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #0000ff">int</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">; i</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> n</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">++</span>
				<span style="COLOR: #000000">i ){<br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( d[i]</span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000"> d[i</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">] ) idx[i]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">pos;<br />        </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000"> idx[i]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> idx[i</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">];<br />        f[ idx[i] ]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> d[i];<br />    }<br />    sort( xyh, xyh</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> n );<br />    </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> i</span>
				<span style="COLOR: #000000">=</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">i ){<br />        a</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> bsearch( xyh[i].x ), b</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> bsearch( xyh[i].y );<br />        insert( </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, pos, a, b, </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, xyh[i].ht );<br />    }        <br />    ans</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">; <br />    sum( </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, pos, </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> );<br />    printf(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">%I64d\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, ans );<br />    <br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />}<br /><br /></span>
		</div>
<img src ="http://www.cppblog.com/Darren/aggbug/90128.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Darren/" target="_blank">Darren</a> 2009-07-15 12:39 <a href="http://www.cppblog.com/Darren/archive/2009/07/15/90128.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Pku  2528  Mayor's posters</title><link>http://www.cppblog.com/Darren/archive/2009/07/14/90068.html</link><dc:creator>Darren</dc:creator><author>Darren</author><pubDate>Tue, 14 Jul 2009 12:19:00 GMT</pubDate><guid>http://www.cppblog.com/Darren/archive/2009/07/14/90068.html</guid><wfw:comment>http://www.cppblog.com/Darren/comments/90068.html</wfw:comment><comments>http://www.cppblog.com/Darren/archive/2009/07/14/90068.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Darren/comments/commentRss/90068.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Darren/services/trackbacks/90068.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">algorithm</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<br />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><br /></span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000"> N 10010</span>
				<span style="COLOR: #000000">
						<br />
						<br />
				</span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> Node{<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> x, y;<br />    Node( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a</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: #0000ff">int</span>
				<span style="COLOR: #000000"> b</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> ):x(a), y(b) {}<br />};<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">  n, idx[N</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">2</span>
				<span style="COLOR: #000000">], data[N</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">2</span>
				<span style="COLOR: #000000">], pos;<br />Node d[N];<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> bfind( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> v ){<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> left</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">, right</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> n</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">2</span>
				<span style="COLOR: #000000">;<br />    </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000">( left</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> right ){<br />        </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> m</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> (left</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> right)</span>
				<span style="COLOR: #000000">&gt;&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">;<br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( data[m]</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> v ) left</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> m;<br />        </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( data[m]</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> v ) right</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> m;<br />        </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> idx[m];<br />    }<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> idx[left];<br />}<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> tb[N</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">8</span>
				<span style="COLOR: #000000">], flag[N];<br /></span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> insert( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> l, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> r, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> b, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> rt, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> c ){<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( l</span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> a </span>
				<span style="COLOR: #000000">&amp;&amp;</span>
				<span style="COLOR: #000000"> r</span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> b ){<br />        tb[rt]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> c; </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000">; }<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> m</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> (l</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> r)</span>
				<span style="COLOR: #000000">&gt;&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">;<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( tb[rt]</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> ){<br />        tb[rt</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"> tb[rt], tb[(rt</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"> tb[rt], tb[rt]</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: #0000ff">if</span>
				<span style="COLOR: #000000">( b</span>
				<span style="COLOR: #000000">&lt;=</span>
				<span style="COLOR: #000000"> m ) insert( l, m, a, b, rt</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, c );<br />    </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( a</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> m ) insert( m</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, r, a, b, (rt</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">, c );<br />    </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">{<br />        insert( l, m, a, m, rt</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, c );<br />        insert( m</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, r, m</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, b, (rt</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">, c ); }<br />}<br /></span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> calc( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> l, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> r, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> rt ){<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( tb[rt]</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> ) { flag[ tb[rt] ]</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: #0000ff">return</span>
				<span style="COLOR: #000000">; }<br />    </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">{<br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( l</span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> r ) </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000">;<br />        </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> m</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> (l</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> r)</span>
				<span style="COLOR: #000000">&gt;&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">;<br />        calc( l, m, rt</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> );<br />        calc( m</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, r, (rt</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"> );<br />    }<br />}<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main(){<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> test;<br />    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: #0000ff">while</span>
				<span style="COLOR: #000000">( test</span>
				<span style="COLOR: #000000">--</span>
				<span style="COLOR: #000000"> ){<br />        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: #0000ff">int</span>
				<span style="COLOR: #000000"> u, v;<br />        </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> i</span>
				<span style="COLOR: #000000">=</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">i ){<br />            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">u,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">v );<br />            d[i]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> Node( u, v );<br />            data[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"> u, data[(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"> v;<br />        }<br />        sort( data, data</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> n</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">2</span>
				<span style="COLOR: #000000"> );<br />        pos</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">; idx[</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">1</span>
				<span style="COLOR: #000000">;<br />        </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #0000ff">int</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">; i</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> n</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">++</span>
				<span style="COLOR: #000000">i )<br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( data[i]</span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000"> data[i</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">] ) idx[i]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">pos;<br />        </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">  idx[i]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> pos;<br />        <br />        memset( tb, </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #0000ff">sizeof</span>
				<span style="COLOR: #000000">(tb) ); <br />        memset( flag, </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #0000ff">sizeof</span>
				<span style="COLOR: #000000">(flag) );<br />        </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> i</span>
				<span style="COLOR: #000000">=</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">i ){<br />            u</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> bfind( d[i].x ), v</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> bfind( d[i].y );<br />            insert( </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, pos, u, v, </span>
				<span style="COLOR: #000000">1</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"> );<br />        }<br />        calc( </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, pos, </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> );<br />        </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> ans</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: #0000ff">for</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #0000ff">int</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">; i</span>
				<span style="COLOR: #000000">&lt;=</span>
				<span style="COLOR: #000000"> n; </span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">i )<br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( flag[i] ) ans</span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">;<br />        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 />    }<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />}<br /></span>
		</div>
<img src ="http://www.cppblog.com/Darren/aggbug/90068.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Darren/" target="_blank">Darren</a> 2009-07-14 20:19 <a href="http://www.cppblog.com/Darren/archive/2009/07/14/90068.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Pku  2985   The k-th Largest Group</title><link>http://www.cppblog.com/Darren/archive/2009/07/14/90014.html</link><dc:creator>Darren</dc:creator><author>Darren</author><pubDate>Tue, 14 Jul 2009 05:31:00 GMT</pubDate><guid>http://www.cppblog.com/Darren/archive/2009/07/14/90014.html</guid><wfw:comment>http://www.cppblog.com/Darren/comments/90014.html</wfw:comment><comments>http://www.cppblog.com/Darren/archive/2009/07/14/90014.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Darren/comments/commentRss/90014.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Darren/services/trackbacks/90014.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<br />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n, m;<br /></span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000"> N  200010</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000"> lowbit(x)  ( (x)&amp;(-(x)) )</span>
				<span style="COLOR: #000000">
						<br />
						<br />
				</span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> TArray{<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> cnt[N];<br />    TArray(){ init(); }<br />    </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> update( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> p, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> v ){<br />        </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> x</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> p; x</span>
				<span style="COLOR: #000000">&lt;=</span>
				<span style="COLOR: #000000"> n; cnt[x]</span>
				<span style="COLOR: #000000">+=</span>
				<span style="COLOR: #000000"> v, x</span>
				<span style="COLOR: #000000">+=</span>
				<span style="COLOR: #000000"> lowbit(x) ); }<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">  sum( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> p ){<br />        </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> x</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> p, s</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: #0000ff">for</span>
				<span style="COLOR: #000000">( ; x; s</span>
				<span style="COLOR: #000000">+=</span>
				<span style="COLOR: #000000"> cnt[x], x</span>
				<span style="COLOR: #000000">-=</span>
				<span style="COLOR: #000000"> lowbit(x) );<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> s; }<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">  rank( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> k ){<br />        k</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> sum(n)</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"> k;<br />        </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> left</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, right</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> n;<br />        </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000">( left</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> right ){<br />            </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> m</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> (left</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> right)</span>
				<span style="COLOR: #000000">&gt;&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">;<br />            </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> s</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> sum(m);<br />            </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( s</span>
				<span style="COLOR: #000000">&gt;=</span>
				<span style="COLOR: #000000"> k ) right</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> m;<br />            </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">        left</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> m;<br />        }<br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( sum(left)</span>
				<span style="COLOR: #000000">&gt;=</span>
				<span style="COLOR: #000000"> k ) </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> left;<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> right;<br />    }<br />    </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> init(){  </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> i</span>
				<span style="COLOR: #000000">=</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">i ) cnt[i]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">; }<br />};<br /><br />TArray tay;<br /></span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> U_find{<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> find[N], num[N];<br />    U_find(){ clear();}<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> parent( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> t ){ <br />        </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> u</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> t, v;   </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000">( u</span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000"> find[u] ) u</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> find[u];<br />        </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000">( t</span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000"> u ) { v</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> find[t]; find[t]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> u; t</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> find[v]; }<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> u;  }<br />    </span>
				<span style="COLOR: #0000ff">bool</span>
				<span style="COLOR: #000000"> is_friend( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> u, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> v ){ </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> parent(u)</span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> parent(v); }<br />    </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> set_friend( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> u, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> v ){<br />        </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> parent(u), b</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> parent(v);<br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( a</span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> b ) </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000">;<br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( num[a]</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> num[b] ) { <br />            find[b]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> a;  <br />            tay.update( num[b], </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> );<br />            tay.update( num[a], </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> );<br />            num[a]</span>
				<span style="COLOR: #000000">+=</span>
				<span style="COLOR: #000000"> num[b];<br />            tay.update( num[a], </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> );<br />        }<br />        </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000"> {<br />            find[a]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> b;<br />            tay.update(  num[a], </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> );<br />            tay.update(  num[b], </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> );<br />            num[b]</span>
				<span style="COLOR: #000000">+=</span>
				<span style="COLOR: #000000"> num[a];<br />            tay.update( num[b], </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> );<br />        }<br />    }<br />    </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> clear(){ </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> i</span>
				<span style="COLOR: #000000">=</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">i ) find[i]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> i, num[i]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">; }<br />};<br /><br />U_find uf;<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main(){<br />    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 />    tay.update( </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, n );<br />    <br />    </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000">( m</span>
				<span style="COLOR: #000000">--</span>
				<span style="COLOR: #000000"> ){<br />        </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> t, u, v, k;<br />        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: #0000ff">if</span>
				<span style="COLOR: #000000">( t</span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> ){<br />            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">u,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">v );<br />            uf.set_friend( u, v  );<br />        }<br />        </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">{<br />            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">k );<br />            printf(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">%d\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, tay.rank(k) );<br />        }<br />    }<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />}<br /></span>
		</div>
<img src ="http://www.cppblog.com/Darren/aggbug/90014.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Darren/" target="_blank">Darren</a> 2009-07-14 13:31 <a href="http://www.cppblog.com/Darren/archive/2009/07/14/90014.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Pku  2777  Count Color</title><link>http://www.cppblog.com/Darren/archive/2009/07/14/90001.html</link><dc:creator>Darren</dc:creator><author>Darren</author><pubDate>Tue, 14 Jul 2009 02:50:00 GMT</pubDate><guid>http://www.cppblog.com/Darren/archive/2009/07/14/90001.html</guid><wfw:comment>http://www.cppblog.com/Darren/comments/90001.html</wfw:comment><comments>http://www.cppblog.com/Darren/archive/2009/07/14/90001.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Darren/comments/commentRss/90001.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Darren/services/trackbacks/90001.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">cstdio</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">cstdlib</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">cstring</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<br />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> L, T, O;<br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> tb[</span>
				<span style="COLOR: #000000">300000</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: #0000ff">void</span>
				<span style="COLOR: #000000"> insert( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> l, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> r, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> b, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> rt, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> c ){<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( l</span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> a </span>
				<span style="COLOR: #000000">&amp;&amp;</span>
				<span style="COLOR: #000000"> r</span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> b ){<br />        tb[rt]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> c; </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000">; }<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( tb[rt]</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> ){<br />        tb[rt</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"> tb[rt], tb[(rt</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"> tb[rt]; tb[rt]</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: #0000ff">int</span>
				<span style="COLOR: #000000"> m</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> (l</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> r)</span>
				<span style="COLOR: #000000">&gt;&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">;<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( b</span>
				<span style="COLOR: #000000">&lt;=</span>
				<span style="COLOR: #000000"> m ) insert( l, m, a, b, rt</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, c );<br />    </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( a</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> m ) insert( m</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, r, a, b, (rt</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">, c );<br />    </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000"> {<br />        insert( l, m, a, m, rt</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, c );<br />        insert( m</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, r, m</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, b, (rt</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">, c ); }<br />}<br /></span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> query( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> l, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> r, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> b, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> rt, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000"> ans ){<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( l</span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> a </span>
				<span style="COLOR: #000000">&amp;&amp;</span>
				<span style="COLOR: #000000"> r</span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> b </span>
				<span style="COLOR: #000000">&amp;&amp;</span>
				<span style="COLOR: #000000"> tb[rt]</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> ){<br />        ans</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">tb[rt]); </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000">;  }<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( tb[rt]</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> ){<br />        tb[rt</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"> tb[rt], tb[(rt</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"> tb[rt]; }<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> m</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> (l</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> r)</span>
				<span style="COLOR: #000000">&gt;&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">;<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( b</span>
				<span style="COLOR: #000000">&lt;=</span>
				<span style="COLOR: #000000"> m ) query( l, m, a, b, rt</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, ans );<br />    </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( a</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> m ) query( m</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, r, a, b, (rt</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">, ans );<br />    </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">{<br />        query( l, m, a, m, rt</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, ans );<br />        query( m</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, r, m</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, b, (rt</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">, ans ); }<br />}<br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> getnum( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> t ){<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> ans</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: #0000ff">for</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #0000ff">int</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">; i</span>
				<span style="COLOR: #000000">&lt;=</span>
				<span style="COLOR: #000000"> T; </span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">i )<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( t</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000">i ) ) ans</span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">;<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> ans;}<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main(){<br />    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">L, </span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">T, </span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">O );<br />    tb[</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">;<br />    </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> str[</span>
				<span style="COLOR: #000000">5</span>
				<span style="COLOR: #000000">];<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a, b, c, d;<br />    </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000">( O</span>
				<span style="COLOR: #000000">--</span>
				<span style="COLOR: #000000"> ){<br />        scanf(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">%s</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, str );<br />        </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">C</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> ){<br />            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">a,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">b,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">c );<br />            </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( a</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> b ) { d</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> a; a</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> b; b</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> d; }<br />            insert( </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, L, a, b, </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, c );<br />        }<br />        </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">{<br />            scanf(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">%d%d</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">a,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">b ); c</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: #0000ff">if</span>
				<span style="COLOR: #000000">( a</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> b ) { d</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> a; a</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> b; b</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> d; }<br />            query( </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, L, a, b, </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, c );<br />            printf(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">%d\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, getnum(c) );<br />        }<br />    }<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />}<br /></span>
		</div>
<img src ="http://www.cppblog.com/Darren/aggbug/90001.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Darren/" target="_blank">Darren</a> 2009-07-14 10:50 <a href="http://www.cppblog.com/Darren/archive/2009/07/14/90001.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ZJU  2770   Burn the Linked Camp(差分约束系统)</title><link>http://www.cppblog.com/Darren/archive/2009/07/11/89797.html</link><dc:creator>Darren</dc:creator><author>Darren</author><pubDate>Sat, 11 Jul 2009 07:32:00 GMT</pubDate><guid>http://www.cppblog.com/Darren/archive/2009/07/11/89797.html</guid><wfw:comment>http://www.cppblog.com/Darren/comments/89797.html</wfw:comment><comments>http://www.cppblog.com/Darren/archive/2009/07/11/89797.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Darren/comments/commentRss/89797.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Darren/services/trackbacks/89797.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">vector</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<br />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><br /></span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> Edge{<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> u, v, w;<br />    Edge( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a</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: #0000ff">int</span>
				<span style="COLOR: #000000"> b</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: #0000ff">int</span>
				<span style="COLOR: #000000"> c</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> ):<br />        u(a), v(b), w(c) {}<br />};<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n, m;<br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> c[</span>
				<span style="COLOR: #000000">1010</span>
				<span style="COLOR: #000000">], sum[</span>
				<span style="COLOR: #000000">1010</span>
				<span style="COLOR: #000000">], dist[</span>
				<span style="COLOR: #000000">1010</span>
				<span style="COLOR: #000000">];<br />vector</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">Edge</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> ege;<br /><br /></span>
				<span style="COLOR: #0000ff">bool</span>
				<span style="COLOR: #000000"> bellman(){<br />    memset( dist, </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #0000ff">sizeof</span>
				<span style="COLOR: #000000">(dist) );    <br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> len</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> ege.size();<br />    </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> i</span>
				<span style="COLOR: #000000">=</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">i ){<br />        </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> j</span>
				<span style="COLOR: #000000">=</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"> len; </span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">j )<br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( dist[ ege[j].u ]</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> ege[j].w</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> dist[ ege[j].v ] )<br />        dist[ ege[j].v ]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> dist[ ege[j].u ]</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> ege[j].w;<br />    }<br />    </span>
				<span style="COLOR: #0000ff">bool</span>
				<span style="COLOR: #000000"> flag</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">false</span>
				<span style="COLOR: #000000">;<br />    </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> j</span>
				<span style="COLOR: #000000">=</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"> len; </span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">j )<br />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( dist[ ege[j].u ]</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> ege[j].w</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> dist[ ege[j].v ] )<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">false</span>
				<span style="COLOR: #000000">;<br />    <br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">true</span>
				<span style="COLOR: #000000">;<br />}<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main(){<br />    </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000">( 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)</span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000"> EOF ){<br />        memset( sum, </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #0000ff">sizeof</span>
				<span style="COLOR: #000000">(sum) );<br />        </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #0000ff">int</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">; i</span>
				<span style="COLOR: #000000">&lt;=</span>
				<span style="COLOR: #000000"> n; </span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">i ){<br />             scanf(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">%d</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, c</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000"> i );<br />             sum[i]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> sum[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"> c[i];<br />             ege.push_back( Edge( i</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, i, c[i] ) );<br />             ege.push_back( Edge( i, i</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> ) );<br />        }<br />        </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> u, v, w;<br />        </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000">( m</span>
				<span style="COLOR: #000000">--</span>
				<span style="COLOR: #000000"> ){<br />            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">u,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">v,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">w );<br />            u</span>
				<span style="COLOR: #000000">--</span>
				<span style="COLOR: #000000">;<br />            ege.push_back( Edge( v, u, </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">w ) );<br />            ege.push_back( Edge( u, v, sum[v]</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000"> sum[u] ) );<br />        }<br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( </span>
				<span style="COLOR: #000000">!</span>
				<span style="COLOR: #000000">bellman() ) puts(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">Bad Estimations</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />        </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">             printf(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">%d\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,dist[n]</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000"> dist[</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">] );<br />        <br />        ege.clear();<br />    }<br />    <br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />}<br /></span>
		</div>
<img src ="http://www.cppblog.com/Darren/aggbug/89797.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Darren/" target="_blank">Darren</a> 2009-07-11 15:32 <a href="http://www.cppblog.com/Darren/archive/2009/07/11/89797.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Pku  2777  Count Color</title><link>http://www.cppblog.com/Darren/archive/2008/10/12/63794.html</link><dc:creator>Darren</dc:creator><author>Darren</author><pubDate>Sun, 12 Oct 2008 04:45:00 GMT</pubDate><guid>http://www.cppblog.com/Darren/archive/2008/10/12/63794.html</guid><wfw:comment>http://www.cppblog.com/Darren/comments/63794.html</wfw:comment><comments>http://www.cppblog.com/Darren/archive/2008/10/12/63794.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Darren/comments/commentRss/63794.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Darren/services/trackbacks/63794.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include </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 />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </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 />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">algorithm</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000"> single(x) ( ( (x)&amp;( (x)-1 ) )== 0 )</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000">  Node<br /><img id="Codehighlighter1_118_168_Open_Image" onclick="this.style.display='none'; Codehighlighter1_118_168_Open_Text.style.display='none'; Codehighlighter1_118_168_Closed_Image.style.display='inline'; Codehighlighter1_118_168_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_118_168_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_118_168_Closed_Text.style.display='none'; Codehighlighter1_118_168_Open_Image.style.display='inline'; Codehighlighter1_118_168_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_118_168_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_118_168_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> left,right,colour;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Node</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> lchild, </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">rchild;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Node</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> create( Node</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> t, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> b )<br /><img id="Codehighlighter1_210_427_Open_Image" onclick="this.style.display='none'; Codehighlighter1_210_427_Open_Text.style.display='none'; Codehighlighter1_210_427_Closed_Image.style.display='inline'; Codehighlighter1_210_427_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_210_427_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_210_427_Closed_Text.style.display='none'; Codehighlighter1_210_427_Open_Image.style.display='inline'; Codehighlighter1_210_427_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_210_427_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_210_427_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    t</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> Node;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    t</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">left</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> a; t</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">right</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> b; t</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">colour</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    t</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">lchild</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> NULL; t</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">rchild</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img id="Codehighlighter1_316_413_Open_Image" onclick="this.style.display='none'; Codehighlighter1_316_413_Open_Text.style.display='none'; Codehighlighter1_316_413_Closed_Image.style.display='inline'; Codehighlighter1_316_413_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_316_413_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_316_413_Closed_Text.style.display='none'; Codehighlighter1_316_413_Open_Image.style.display='inline'; Codehighlighter1_316_413_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">( a</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> b )</span>
						<span id="Codehighlighter1_316_413_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_316_413_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        t</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">lchild</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> create( t</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">lchild, a, (a</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">b)</span>
								<span style="COLOR: #000000">/</span>
								<span style="COLOR: #000000">2</span>
								<span style="COLOR: #000000"> );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        t</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">rchild</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> create( t</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">rchild, (a</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">b)</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">, b );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> t;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> insert( Node</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> root, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a,</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> b, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> c )<br /><img id="Codehighlighter1_476_1034_Open_Image" onclick="this.style.display='none'; Codehighlighter1_476_1034_Open_Text.style.display='none'; Codehighlighter1_476_1034_Closed_Image.style.display='inline'; Codehighlighter1_476_1034_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_476_1034_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_476_1034_Closed_Text.style.display='none'; Codehighlighter1_476_1034_Open_Image.style.display='inline'; Codehighlighter1_476_1034_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_476_1034_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_476_1034_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">( root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">left</span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> a </span>
						<span style="COLOR: #000000">&amp;&amp;</span>
						<span style="COLOR: #000000"> root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">right</span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> b </span>
						<span style="COLOR: #000000">||</span>
						<span style="COLOR: #000000"> root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">colour</span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> c )<br /><img id="Codehighlighter1_540_572_Open_Image" onclick="this.style.display='none'; Codehighlighter1_540_572_Open_Text.style.display='none'; Codehighlighter1_540_572_Closed_Image.style.display='inline'; Codehighlighter1_540_572_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_540_572_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_540_572_Closed_Text.style.display='none'; Codehighlighter1_540_572_Open_Image.style.display='inline'; Codehighlighter1_540_572_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_540_572_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_540_572_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        root</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">colour</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> c;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">( single(root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">colour ) )<br /><img id="Codehighlighter1_605_682_Open_Image" onclick="this.style.display='none'; Codehighlighter1_605_682_Open_Text.style.display='none'; Codehighlighter1_605_682_Closed_Image.style.display='inline'; Codehighlighter1_605_682_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_605_682_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_605_682_Closed_Text.style.display='none'; Codehighlighter1_605_682_Open_Image.style.display='inline'; Codehighlighter1_605_682_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_605_682_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_605_682_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        root</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">lchild</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">colour</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">root</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">colour;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        root</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">rchild</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">colour</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">root</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">colour;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> middle</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> (root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">left</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">right)</span>
						<span style="COLOR: #000000">/</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">2</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">( b</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000"> middle )      insert( root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">lchild, a, b, c );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">( a</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> middle )  insert( root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">rchild, a, b, c );<br /><img id="Codehighlighter1_848_934_Open_Image" onclick="this.style.display='none'; Codehighlighter1_848_934_Open_Text.style.display='none'; Codehighlighter1_848_934_Closed_Image.style.display='inline'; Codehighlighter1_848_934_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_848_934_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_848_934_Closed_Text.style.display='none'; Codehighlighter1_848_934_Open_Image.style.display='inline'; Codehighlighter1_848_934_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span id="Codehighlighter1_848_934_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_848_934_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        insert( root</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">lchild, a, middle, c );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        insert( root</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">rchild, middle</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">, b, c );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">( root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">lchild </span>
						<span style="COLOR: #000000">&amp;&amp;</span>
						<span style="COLOR: #000000"> root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">rchild )<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">colour</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">lchild</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">colour </span>
						<span style="COLOR: #000000">|</span>
						<span style="COLOR: #000000"> root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">rchild</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">colour;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> getcout( Node</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> root, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> b, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000"> cnt )<br /><img id="Codehighlighter1_1088_1466_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1088_1466_Open_Text.style.display='none'; Codehighlighter1_1088_1466_Closed_Image.style.display='inline'; Codehighlighter1_1088_1466_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1088_1466_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1088_1466_Closed_Text.style.display='none'; Codehighlighter1_1088_1466_Open_Image.style.display='inline'; Codehighlighter1_1088_1466_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1088_1466_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1088_1466_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">( root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">left</span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> a </span>
						<span style="COLOR: #000000">&amp;&amp;</span>
						<span style="COLOR: #000000"> root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">right</span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> b </span>
						<span style="COLOR: #000000">||</span>
						<span style="COLOR: #000000"> single(root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">colour ) )<br /><img id="Codehighlighter1_1157_1195_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1157_1195_Open_Text.style.display='none'; Codehighlighter1_1157_1195_Closed_Image.style.display='inline'; Codehighlighter1_1157_1195_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1157_1195_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1157_1195_Closed_Text.style.display='none'; Codehighlighter1_1157_1195_Open_Image.style.display='inline'; Codehighlighter1_1157_1195_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_1157_1195_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1157_1195_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        cnt</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> cnt</span>
								<span style="COLOR: #000000">|</span>
								<span style="COLOR: #000000">root</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">colour;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> middle</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> (root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">left</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">right)</span>
						<span style="COLOR: #000000">/</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">2</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">( b</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000"> middle )       getcout( root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">lchild, a, b, cnt );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">( a</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> middle )   getcout( root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">rchild, a, b, cnt );<br /><img id="Codehighlighter1_1369_1464_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1369_1464_Open_Text.style.display='none'; Codehighlighter1_1369_1464_Closed_Image.style.display='inline'; Codehighlighter1_1369_1464_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1369_1464_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1369_1464_Closed_Text.style.display='none'; Codehighlighter1_1369_1464_Open_Image.style.display='inline'; Codehighlighter1_1369_1464_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span id="Codehighlighter1_1369_1464_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1369_1464_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        getcout( root</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">lchild, a, middle,    cnt );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        getcout( root</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">rchild, middle</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">, b, cnt );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> count( </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> i )<br /><img id="Codehighlighter1_1488_1565_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1488_1565_Open_Text.style.display='none'; Codehighlighter1_1488_1565_Closed_Image.style.display='inline'; Codehighlighter1_1488_1565_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1488_1565_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1488_1565_Closed_Text.style.display='none'; Codehighlighter1_1488_1565_Open_Image.style.display='inline'; Codehighlighter1_1488_1565_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1488_1565_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1488_1565_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> ans</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000">( i</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000"> )<br /><img id="Codehighlighter1_1519_1550_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1519_1550_Open_Text.style.display='none'; Codehighlighter1_1519_1550_Closed_Image.style.display='inline'; Codehighlighter1_1519_1550_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1519_1550_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1519_1550_Closed_Text.style.display='none'; Codehighlighter1_1519_1550_Open_Image.style.display='inline'; Codehighlighter1_1519_1550_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_1519_1550_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1519_1550_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">( i</span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000"> ) ans</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        i</span>
								<span style="COLOR: #000000">&gt;&gt;=</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> ans;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_1581_2072_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1581_2072_Open_Text.style.display='none'; Codehighlighter1_1581_2072_Closed_Image.style.display='inline'; Codehighlighter1_1581_2072_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1581_2072_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1581_2072_Closed_Text.style.display='none'; Codehighlighter1_1581_2072_Open_Image.style.display='inline'; Codehighlighter1_1581_2072_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1581_2072_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1581_2072_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Node</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> root;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> l, t, o;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    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">l,</span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000">t,</span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000">o );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    root</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> create( root, </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">,l );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">char</span>
						<span style="COLOR: #000000"> str[</span>
						<span style="COLOR: #000000">5</span>
						<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000">( </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i</span>
						<span style="COLOR: #000000">=</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"> o; </span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">i )<br /><img id="Codehighlighter1_1713_2058_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1713_2058_Open_Text.style.display='none'; Codehighlighter1_1713_2058_Closed_Image.style.display='inline'; Codehighlighter1_1713_2058_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1713_2058_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1713_2058_Closed_Text.style.display='none'; Codehighlighter1_1713_2058_Open_Image.style.display='inline'; Codehighlighter1_1713_2058_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_1713_2058_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1713_2058_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        scanf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">%s</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">,str);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </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">C</span>
								<span style="COLOR: #000000">'</span>
								<span style="COLOR: #000000"> )<br /><img id="Codehighlighter1_1760_1879_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1760_1879_Open_Text.style.display='none'; Codehighlighter1_1760_1879_Closed_Image.style.display='inline'; Codehighlighter1_1760_1879_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1760_1879_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1760_1879_Closed_Text.style.display='none'; Codehighlighter1_1760_1879_Open_Image.style.display='inline'; Codehighlighter1_1760_1879_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_1760_1879_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_1760_1879_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> x, y, z;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            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">x,</span>
										<span style="COLOR: #000000">&amp;</span>
										<span style="COLOR: #000000">y,</span>
										<span style="COLOR: #000000">&amp;</span>
										<span style="COLOR: #000000">z);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000">( x</span>
										<span style="COLOR: #000000">&gt;</span>
										<span style="COLOR: #000000"> y ) std::swap(x,y);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            insert( root, x, y, </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">&lt;&lt;</span>
										<span style="COLOR: #000000">(z</span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">) );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000"> </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">P</span>
								<span style="COLOR: #000000">'</span>
								<span style="COLOR: #000000"> )<br /><img id="Codehighlighter1_1909_2055_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1909_2055_Open_Text.style.display='none'; Codehighlighter1_1909_2055_Closed_Image.style.display='inline'; Codehighlighter1_1909_2055_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1909_2055_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1909_2055_Closed_Text.style.display='none'; Codehighlighter1_1909_2055_Open_Image.style.display='inline'; Codehighlighter1_1909_2055_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_1909_2055_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_1909_2055_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> x, y,cnt</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            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">x,</span>
										<span style="COLOR: #000000">&amp;</span>
										<span style="COLOR: #000000">y);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000">( x</span>
										<span style="COLOR: #000000">&gt;</span>
										<span style="COLOR: #000000"> y ) std::swap(x,y);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            getcout( root, x, y, cnt );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            printf(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">%d\n</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">, count(cnt) );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
<img src ="http://www.cppblog.com/Darren/aggbug/63794.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Darren/" target="_blank">Darren</a> 2008-10-12 12:45 <a href="http://www.cppblog.com/Darren/archive/2008/10/12/63794.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Zoj  1610  Count the Colors</title><link>http://www.cppblog.com/Darren/archive/2008/10/08/63459.html</link><dc:creator>Darren</dc:creator><author>Darren</author><pubDate>Wed, 08 Oct 2008 06:29:00 GMT</pubDate><guid>http://www.cppblog.com/Darren/archive/2008/10/08/63459.html</guid><wfw:comment>http://www.cppblog.com/Darren/comments/63459.html</wfw:comment><comments>http://www.cppblog.com/Darren/archive/2008/10/08/63459.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/Darren/comments/commentRss/63459.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Darren/services/trackbacks/63459.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include </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 />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </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 />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </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 />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000"> NOC -1</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000"> MUC -2</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000"> N   8001</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000"> M   10000</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000">  Node<br /><img id="Codehighlighter1_139_249_Open_Image" onclick="this.style.display='none'; Codehighlighter1_139_249_Open_Text.style.display='none'; Codehighlighter1_139_249_Closed_Image.style.display='inline'; Codehighlighter1_139_249_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_139_249_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_139_249_Closed_Text.style.display='none'; Codehighlighter1_139_249_Open_Image.style.display='inline'; Codehighlighter1_139_249_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_139_249_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_139_249_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">  leftvalue;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">  rightvalue;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">  colour;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Node</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">  leftchild;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Node</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">  rightchild;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">   colour[M];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Node</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> create( Node</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> r, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> left, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> right )<br /><img id="Codehighlighter1_315_733_Open_Image" onclick="this.style.display='none'; Codehighlighter1_315_733_Open_Text.style.display='none'; Codehighlighter1_315_733_Closed_Image.style.display='inline'; Codehighlighter1_315_733_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_315_733_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_315_733_Closed_Text.style.display='none'; Codehighlighter1_315_733_Open_Image.style.display='inline'; Codehighlighter1_315_733_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_315_733_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_315_733_Open_Text">
						<span style="COLOR: #000000">{    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Node</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> temp</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> Node;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    temp</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">leftvalue</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> left;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    temp</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">rightvalue</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> right;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    temp</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">colour</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> NOC;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    temp</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">rightchild</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    temp</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">leftchild</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> ( right</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> left</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: #0000ff">return</span>
						<span style="COLOR: #000000"> temp;<br /><img id="Codehighlighter1_548_709_Open_Image" onclick="this.style.display='none'; Codehighlighter1_548_709_Open_Text.style.display='none'; Codehighlighter1_548_709_Closed_Image.style.display='inline'; Codehighlighter1_548_709_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_548_709_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_548_709_Closed_Text.style.display='none'; Codehighlighter1_548_709_Open_Image.style.display='inline'; Codehighlighter1_548_709_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span id="Codehighlighter1_548_709_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_548_709_Open_Text">
								<span style="COLOR: #000000">{ <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        temp</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">leftchild</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> create( temp</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">leftchild, left, (left</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> right)</span>
								<span style="COLOR: #000000">/</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">2</span>
								<span style="COLOR: #000000"> );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        temp</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">rightchild</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> create( temp</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">rightchild, (left</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">right)</span>
								<span style="COLOR: #000000">/</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">2</span>
								<span style="COLOR: #000000">, right );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> temp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">       <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> insert( Node</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> tree, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> left, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> right, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> c )<br /><img id="Codehighlighter1_797_1469_Open_Image" onclick="this.style.display='none'; Codehighlighter1_797_1469_Open_Text.style.display='none'; Codehighlighter1_797_1469_Closed_Image.style.display='inline'; Codehighlighter1_797_1469_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_797_1469_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_797_1469_Closed_Text.style.display='none'; Codehighlighter1_797_1469_Open_Image.style.display='inline'; Codehighlighter1_797_1469_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_797_1469_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_797_1469_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> middle</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> ( tree</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">leftvalue</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> tree</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">rightvalue )</span>
						<span style="COLOR: #000000">/</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">2</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> ( right</span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> tree</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">rightvalue </span>
						<span style="COLOR: #000000">&amp;&amp;</span>
						<span style="COLOR: #000000"> left</span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> tree</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">leftvalue </span>
						<span style="COLOR: #000000">||</span>
						<span style="COLOR: #000000"> tree</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">colour</span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> c)<br /><img id="Codehighlighter1_947_995_Open_Image" onclick="this.style.display='none'; Codehighlighter1_947_995_Open_Text.style.display='none'; Codehighlighter1_947_995_Closed_Image.style.display='inline'; Codehighlighter1_947_995_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_947_995_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_947_995_Closed_Text.style.display='none'; Codehighlighter1_947_995_Open_Image.style.display='inline'; Codehighlighter1_947_995_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_947_995_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_947_995_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        tree</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">colour</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">  c;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">   <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> ( tree</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">colour </span>
						<span style="COLOR: #000000">&gt;=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000"> )<br /><img id="Codehighlighter1_1038_1139_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1038_1139_Open_Text.style.display='none'; Codehighlighter1_1038_1139_Closed_Image.style.display='inline'; Codehighlighter1_1038_1139_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1038_1139_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1038_1139_Closed_Text.style.display='none'; Codehighlighter1_1038_1139_Open_Image.style.display='inline'; Codehighlighter1_1038_1139_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_1038_1139_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1038_1139_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        tree</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">leftchild</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">colour</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> tree</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">colour;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        tree</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">rightchild</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">colour</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> tree</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">colour;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    tree</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">colour</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> MUC;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> ( middle</span>
						<span style="COLOR: #000000">&gt;=</span>
						<span style="COLOR: #000000"> right )       insert( tree</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">leftchild, left, right, c );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000">  </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> ( middle</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000"> left )  insert( tree</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">rightchild, left, right,c );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_1340_1455_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1340_1455_Open_Text.style.display='none'; Codehighlighter1_1340_1455_Closed_Image.style.display='inline'; Codehighlighter1_1340_1455_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_1340_1455_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1340_1455_Closed_Text.style.display='none'; Codehighlighter1_1340_1455_Open_Image.style.display='inline'; Codehighlighter1_1340_1455_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_1340_1455_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1340_1455_Open_Text">
								<span style="COLOR: #000000">{   <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        insert( tree</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">leftchild, left, middle, c );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        insert( tree</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">rightchild, middle, right, c );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />       <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> getcolour( Node</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> tree, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000"> col )<br /><img id="Codehighlighter1_1512_1806_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1512_1806_Open_Text.style.display='none'; Codehighlighter1_1512_1806_Closed_Image.style.display='inline'; Codehighlighter1_1512_1806_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1512_1806_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1512_1806_Closed_Text.style.display='none'; Codehighlighter1_1512_1806_Open_Image.style.display='inline'; Codehighlighter1_1512_1806_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1512_1806_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1512_1806_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> ( tree</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">colour</span>
						<span style="COLOR: #000000">&gt;=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">&amp;&amp;</span>
						<span style="COLOR: #000000"> tree</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">colour</span>
						<span style="COLOR: #000000">!=</span>
						<span style="COLOR: #000000"> col )<br /><img id="Codehighlighter1_1568_1635_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1568_1635_Open_Text.style.display='none'; Codehighlighter1_1568_1635_Closed_Image.style.display='inline'; Codehighlighter1_1568_1635_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1568_1635_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1568_1635_Closed_Text.style.display='none'; Codehighlighter1_1568_1635_Open_Image.style.display='inline'; Codehighlighter1_1568_1635_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_1568_1635_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1568_1635_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        col</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> tree</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">colour;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        colour[ tree</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">colour ]</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> ( tree</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">colour</span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> MUC )<br /><img id="Codehighlighter1_1680_1773_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1680_1773_Open_Text.style.display='none'; Codehighlighter1_1680_1773_Closed_Image.style.display='inline'; Codehighlighter1_1680_1773_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1680_1773_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1680_1773_Closed_Text.style.display='none'; Codehighlighter1_1680_1773_Open_Image.style.display='inline'; Codehighlighter1_1680_1773_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_1680_1773_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1680_1773_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        getcolour( tree</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">leftchild, col );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        getcolour( tree</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">rightchild, col );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000"> col</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> tree</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">colour;   <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">              <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />            <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_1846_2385_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1846_2385_Open_Text.style.display='none'; Codehighlighter1_1846_2385_Closed_Image.style.display='inline'; Codehighlighter1_1846_2385_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1846_2385_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1846_2385_Closed_Text.style.display='none'; Codehighlighter1_1846_2385_Open_Image.style.display='inline'; Codehighlighter1_1846_2385_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1846_2385_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1846_2385_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Node</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> root;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">   n;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000">( scanf(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">%d</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000">n)</span>
						<span style="COLOR: #000000">!=</span>
						<span style="COLOR: #000000"> EOF )<br /><img id="Codehighlighter1_1920_2360_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1920_2360_Open_Text.style.display='none'; Codehighlighter1_1920_2360_Closed_Image.style.display='inline'; Codehighlighter1_1920_2360_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1920_2360_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1920_2360_Closed_Text.style.display='none'; Codehighlighter1_1920_2360_Open_Image.style.display='inline'; Codehighlighter1_1920_2360_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_1920_2360_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1920_2360_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        root</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> create( root, </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">, N );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000">  a, b, c;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> ( </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> i</span>
								<span style="COLOR: #000000">=</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">i )<br /><img id="Codehighlighter1_2024_2109_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2024_2109_Open_Text.style.display='none'; Codehighlighter1_2024_2109_Closed_Image.style.display='inline'; Codehighlighter1_2024_2109_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_2024_2109_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2024_2109_Closed_Text.style.display='none'; Codehighlighter1_2024_2109_Open_Image.style.display='inline'; Codehighlighter1_2024_2109_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_2024_2109_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_2024_2109_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            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">a,</span>
										<span style="COLOR: #000000">&amp;</span>
										<span style="COLOR: #000000">b,</span>
										<span style="COLOR: #000000">&amp;</span>
										<span style="COLOR: #000000">c);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            insert( root, a, b, c );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        memset( colour, </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #0000ff">sizeof</span>
								<span style="COLOR: #000000">(colour) );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> col</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">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        getcolour( root, col );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> ( </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> i</span>
								<span style="COLOR: #000000">=</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; </span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">i ) <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />          </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> ( colour[i] ) printf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">%d %d\n</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">, i, colour[i] );   <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        printf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">\n</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">);    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">        </span>
		</div>
<img src ="http://www.cppblog.com/Darren/aggbug/63459.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Darren/" target="_blank">Darren</a> 2008-10-08 14:29 <a href="http://www.cppblog.com/Darren/archive/2008/10/08/63459.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>